UNPKG

1.19 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isOverlap = exports.isOverflow = exports.isInBounds = exports.parseAABB = void 0;
4function parseAABB(min2) {
5 const { min, max } = min2;
6 return [
7 [min[0], min[1]],
8 [max[0], max[1]],
9 ];
10}
11exports.parseAABB = parseAABB;
12/**
13 * Whether the `point` in `bounds`.
14 * @param point
15 * @param bounds
16 */
17function isInBounds(point, bounds) {
18 const [x, y] = point;
19 const [min, max] = bounds;
20 return x >= min[0] && x <= max[0] && y >= min[1] && y <= max[1];
21}
22exports.isInBounds = isInBounds;
23/**
24 * Whether `b1` is overflow from `b2`.
25 * @param b1
26 * @param b2
27 */
28function isOverflow(b1, b2) {
29 const [min, max] = b1;
30 return !(isInBounds(min, b2) && isInBounds(max, b2));
31}
32exports.isOverflow = isOverflow;
33/**
34 * Whether `b1` is overlap with `b2`.
35 * @param b1
36 * @param b2
37 * @returns
38 */
39function isOverlap(b1, b2) {
40 const [min1, max1] = b1;
41 const [min2, max2] = b2;
42 return (min1[0] < max2[0] &&
43 max1[0] > min2[0] &&
44 min1[1] < max2[1] &&
45 max1[1] > min2[1]);
46}
47exports.isOverlap = isOverlap;
48//# sourceMappingURL=bounds.js.map
\No newline at end of file