UNPKG

vis-utils

Version:

Utility functions for data visualization

27 lines (25 loc) 892 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = rectIntersects; var X = 0; var Y = 1; var TOP_LEFT = 0; var BOTTOM_RIGHT = 1; /** * Determines if two rectangles intersect. Here a rectangle is defined * by its upper left and lower right corners. * * Note that it is assumed that the top Y value is less than the bottom Y value. * * @param {Number[][]} rect1 The first rectangle, a pair of two points * [[x, y], [x, y]] * @param {Number[][]} rect2 The second rectangle, a pair of two points * [[x, y], [x, y]] * * @return {Boolean} true if the rectangles intersect, false otherwise */ function rectIntersects(rect1, rect2) { return rect1[TOP_LEFT][X] <= rect2[BOTTOM_RIGHT][X] && rect2[TOP_LEFT][X] <= rect1[BOTTOM_RIGHT][X] && rect1[TOP_LEFT][Y] <= rect2[BOTTOM_RIGHT][Y] && rect2[TOP_LEFT][Y] <= rect1[BOTTOM_RIGHT][Y]; }