<commit_before>(function () {
  var ns = $.namespace('pskl');

  ns.PixelUtils = {

    getRectanglePixels : function (x0, y0, x1, y1) {
      var rectangle = this.getOrderedRectangleCoordinates(x0, y0, x1, y1);
      var pixels = [];

      for (var x = rectangle.x0 ; x <= rectangle.x1 ; x++) {
        for (var y = rectangle.y0 ; y <= rectangle.y1 ; y++) {
          pixels.push({'col': x, 'row': y});
        }
      }

      return pixels;
    },

    getBoundRectanglePixels : function (x0, y0, x1, y1) {
      var rectangle = this.getOrderedRectangleCoordinates(x0, y0, x1, y1);
      var pixels = [];
      // Creating horizontal sides of the rectangle:
      for (var x = rectangle.x0; x <= rectangle.x1; x++) {
        pixels.push({'col': x, 'row': rectangle.y0});
        pixels.push({'col': x, 'row': rectangle.y1});
      }

      // Creating vertical sides of the rectangle:
      for (var y = rectangle.y0; y <= rectangle.y1; y++) {
        pixels.push({'col': rectangle.x0, 'row': y});
        pixels.push({'col': rectangle.x1, 'row': y});
      }

      return pixels;
    },

    /**
     * Return an object of ordered rectangle coordinate.
     * In returned object {x0, y0} => top left corner - {x1, y1} => bottom right corner
     * @private
     */
    getOrderedRectangleCoordinates : function (x0, y0, x1, y1) {
      return {
        x0 : Math.min(x0, x1),
        y0 : Math.min(y0, y1),
        x1 : Math.max(x0, x1),
        y1 : Math.max(y0, y1)
      };
    },

    /**
     * Return the list of pixels that would have been filled by a paintbucket tool applied
     * on pixel at coordinate (x,y).
     * This function is not altering the Frame object argument.
     *
     * @param frame pskl.model.Frame The frame target in which we want to paintbucket
     * @param col number Column coordinate in the frame
     * @param row number Row coordinate in the frame
     *
     * @return an array of the pixel coordinates paint with the replacement color
     */
    getSimilarConnectedPixelsFromFrame: function(frame, col, row) {
      var targetColor = frame.getPixel(col, row);
      if (targetColor === null) {
        return;
      }

      var startPixel = {
        col : col,
        row : row
      };

      var visited = {};
      return pskl.PixelUtils.visitConnectedPixels(startPixel, frame, function (pixel) {
        var key = pixel.col + '-' + pixel.row;
        if (visited[key]) {
          return false;
        }
        visited[key] = true;
        return frame.getPixel(pixel.col, pixel.row) == targetColor;
      });
    },

    /**
     * Resize the pixel at {col, row} for the provided size. Will return the array of pixels centered
     * around the original pixel, forming a pixel square of side=size
     *
     * @param  {Number} row  x-coordinate of the original pixel
     * @param  {Number} col  y-coordinate of the original pixel
     * @param  {Number} size >= 1 && <= 32
     * @return {Array}  array of arrays of 2 Numbers (eg. [[0,0], [0,1], [1,0], [1,1]])
     */
    resizePixel : function (col, row, size) {
      var pixels = [];
<commit_msg>fix #603 shape select fails when clicking outside drawing area<commit_after>(function () {
  var ns = $.namespace('pskl');

  ns.PixelUtils = {

    getRectanglePixels : function (x0, y0, x1, y1) {
      var rectangle = this.getOrderedRectangleCoordinates(x0, y0, x1, y1);
      var pixels = [];

      for (var x = rectangle.x0 ; x <= rectangle.x1 ; x++) {
        for (var y = rectangle.y0 ; y <= rectangle.y1 ; y++) {
          pixels.push({'col': x, 'row': y});
        }
      }

      return pixels;
    },

    getBoundRectanglePixels : function (x0, y0, x1, y1) {
      var rectangle = this.getOrderedRectangleCoordinates(x0, y0, x1, y1);
      var pixels = [];
      // Creating horizontal sides of the rectangle:
      for (var x = rectangle.x0; x <= rectangle.x1; x++) {
        pixels.push({'col': x, 'row': rectangle.y0});
        pixels.push({'col': x, 'row': rectangle.y1});
      }

      // Creating vertical sides of the rectangle:
      for (var y = rectangle.y0; y <= rectangle.y1; y++) {
        pixels.push({'col': rectangle.x0, 'row': y});
        pixels.push({'col': rectangle.x1, 'row': y});
      }

      return pixels;
    },

    /**
     * Return an object of ordered rectangle coordinate.
     * In returned object {x0, y0} => top left corner - {x1, y1} => bottom right corner
     * @private
     */
    getOrderedRectangleCoordinates : function (x0, y0, x1, y1) {
      return {
        x0 : Math.min(x0, x1),
        y0 : Math.min(y0, y1),
        x1 : Math.max(x0, x1),
        y1 : Math.max(y0, y1)
      };
    },

    /**
     * Return the list of pixels that would have been filled by a paintbucket tool applied
     * on pixel at coordinate (x,y).
     * This function is not altering the Frame object argument.
     *
     * @param frame pskl.model.Frame The frame target in which we want to paintbucket
     * @param col number Column coordinate in the frame
     * @param row number Row coordinate in the frame
     *
     * @return an array of the pixel coordinates paint with the replacement color
     */
    getSimilarConnectedPixelsFromFrame: function(frame, col, row) {
      var targetColor = frame.getPixel(col, row);
      if (targetColor === null) {
        return [];
      }

      var startPixel = {
        col : col,
        row : row
      };

      var visited = {};
      return pskl.PixelUtils.visitConnectedPixels(startPixel, frame, function (pixel) {
        var key = pixel.col + '-' + pixel.row;
        if (visited[key]) {
          return false;
        }
        visited[key] = true;
        return frame.getPixel(pixel.col, pixel.row) == targetColor;
      });
    },

    /**
     * Resize the pixel at {col, row} for the provided size. Will return the array of pixels centered
     * around the original pixel, forming a pixel square of side=size
     *
     * @param  {Number} row  x-coordinate of the original pixel
     * @param  {Number} col  y-coordinate of the original pixel
     * @param  {Number} size >= 1 && <= 32
     * @return {Array}  array of arrays of 2 Numbers (eg. [[0,0], [0,1], [1,0], [1,1]])
     */
    resizePixel : function (col, row, size) {
      var pixels = [];

{'fraction_non_alphanumeric': 0.13153698979591838, 'fraction_numerical': 0.0196109693877551, 'mean_word_length': 2.2251928020565552, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1045709', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1964, 'n_words': 635}