vis-utils
Version:
Utility functions for data visualization
27 lines (25 loc) • 841 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = rectContains;
var X = 0;
var Y = 1;
var TOP_LEFT = 0;
var BOTTOM_RIGHT = 1;
/**
* Determines if a point is inside a rectangle. The rectangle is
* defined by two points:
* - the upper left corner (rx1, ry1)
* - the bottom right corner (rx2, ry2)
* Note that it is assumed that the top Y value is less than the bottom Y value.
*
* @param {Number[][]} rect The rectangle, a pair of two points
* [[x, y], [x, y]]
* @param {Number[]} point The point ([x, y])
*
* @return {Boolean} true if the point is inside the rectangle, false otherwise
*/
function rectContains(rect, point) {
return rect[TOP_LEFT][X] <= point[X] && point[X] <= rect[BOTTOM_RIGHT][X] && rect[TOP_LEFT][Y] <= point[Y] && point[Y] <= rect[BOTTOM_RIGHT][Y];
}