arty-charty/util.js
function findRectangleIndexContainingPoint(rectangles, x, y) {
    let closestIdx;
    rectangles.some((d, idx) => {
      if ((d.x1 <= x && x <= d.x2) && (d.y1 <= y && y <= d.y2)) {
        closestIdx = idx;
        return true;
      }
      return false;
    });
    return closestIdx;
  }
function findRectangleIndexContainingPoint(rectangles, x, y) {
    let closestIdx;
    rectangles.some((d, idx) => {
      if ((d.x1 <= x && x <= d.x2) && (d.y1 <= y && y <= d.y2)) {
        closestIdx = idx;
        return true;
      }
      return false;
    });
    return closestIdx;
  }
function findRectangleIndexContainingPoint ( rectangles , x , y ) { let closestIdx ; rectangles . some ( ( d , idx ) => { if ( ( d . x1 <= x && x <= d . x2 ) && ( d . y1 <= y && y <= d . y2 ) ) { closestIdx = idx ; return true ; } return false ; } ) ; return closestIdx ; }
Find the index of the rectangle that contains a given
coordinate.
@param {array} points - Array of rectangles, each rectangle is of the form
{x1: number, x2: number, y1: number, y2: number},
where x1 and x2 are the minimum and maximum x coordinates
and y1 and y3 are the minimum and maximum x coordinates.
@param {number} x     - The x coordinate
@param {number} y     - The y coordinate
Find the index of the rectangle that contains a given coordinate .