@zag-js/rect-utils 0.10.1 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/align.d.ts +5 -9
- package/dist/align.js +5 -28
- package/dist/align.mjs +44 -6
- package/dist/closest.d.ts +5 -8
- package/dist/closest.js +8 -38
- package/dist/closest.mjs +47 -13
- package/dist/contains.d.ts +5 -8
- package/dist/contains.js +9 -48
- package/dist/contains.mjs +13 -11
- package/dist/distance.d.ts +7 -10
- package/dist/distance.js +9 -40
- package/dist/distance.mjs +41 -14
- package/dist/from-element.d.ts +3 -7
- package/dist/from-element.js +9 -53
- package/dist/from-element.mjs +39 -7
- package/dist/from-points.d.ts +3 -6
- package/dist/from-points.js +6 -50
- package/dist/from-points.mjs +13 -7
- package/dist/from-range.d.ts +2 -6
- package/dist/from-range.js +11 -127
- package/dist/from-range.mjs +23 -10
- package/dist/from-rotation.d.ts +5 -8
- package/dist/from-rotation.js +9 -62
- package/dist/from-rotation.mjs +33 -11
- package/dist/from-window.d.ts +4 -8
- package/dist/from-window.js +7 -52
- package/dist/from-window.mjs +21 -9
- package/dist/get-polygon.d.ts +2 -5
- package/dist/get-polygon.js +7 -58
- package/dist/get-polygon.mjs +15 -7
- package/dist/index.d.ts +16 -16
- package/dist/index.js +58 -539
- package/dist/index.mjs +15 -105
- package/dist/intersection.d.ts +5 -8
- package/dist/intersection.js +8 -54
- package/dist/intersection.mjs +22 -11
- package/dist/operations.d.ts +7 -10
- package/dist/operations.js +12 -60
- package/dist/operations.mjs +32 -15
- package/dist/polygon.d.ts +3 -6
- package/dist/polygon.js +6 -30
- package/dist/polygon.mjs +48 -8
- package/dist/rect.d.ts +7 -10
- package/dist/rect.js +11 -38
- package/dist/rect.mjs +47 -14
- package/dist/types.d.ts +13 -15
- package/dist/union.d.ts +2 -6
- package/dist/union.js +7 -62
- package/dist/union.mjs +28 -8
- package/package.json +2 -7
- package/dist/chunk-25JXNQDO.mjs +0 -32
- package/dist/chunk-2FRM3R57.mjs +0 -27
- package/dist/chunk-62GE3RPG.mjs +0 -21
- package/dist/chunk-BDA5H4ND.mjs +0 -44
- package/dist/chunk-BRVYSREB.mjs +0 -21
- package/dist/chunk-D46YBNP3.mjs +0 -18
- package/dist/chunk-GYYHT756.mjs +0 -29
- package/dist/chunk-K4PDUEML.mjs +0 -33
- package/dist/chunk-MM5LIN7D.mjs +0 -41
- package/dist/chunk-MNKJK37U.mjs +0 -54
- package/dist/chunk-N5AQDOKZ.mjs +0 -49
- package/dist/chunk-Q4ND66B6.mjs +0 -54
- package/dist/chunk-QXXKPYP2.mjs +0 -47
- package/dist/chunk-R24UTBJ3.mjs +0 -52
- package/dist/chunk-W5IPBTYQ.mjs +0 -41
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,105 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from
|
|
15
|
-
|
|
16
|
-
debugPolygon,
|
|
17
|
-
isPointInPolygon
|
|
18
|
-
} from "./chunk-R24UTBJ3.mjs";
|
|
19
|
-
import "./chunk-WBQAMGXK.mjs";
|
|
20
|
-
import {
|
|
21
|
-
alignRect
|
|
22
|
-
} from "./chunk-QXXKPYP2.mjs";
|
|
23
|
-
import {
|
|
24
|
-
closest,
|
|
25
|
-
closestSideToPoint,
|
|
26
|
-
closestSideToRect
|
|
27
|
-
} from "./chunk-Q4ND66B6.mjs";
|
|
28
|
-
import {
|
|
29
|
-
contains,
|
|
30
|
-
containsPoint,
|
|
31
|
-
containsRect
|
|
32
|
-
} from "./chunk-62GE3RPG.mjs";
|
|
33
|
-
import {
|
|
34
|
-
distance,
|
|
35
|
-
distanceBtwEdges,
|
|
36
|
-
distanceFromPoint,
|
|
37
|
-
distanceFromRect
|
|
38
|
-
} from "./chunk-N5AQDOKZ.mjs";
|
|
39
|
-
import {
|
|
40
|
-
collisions,
|
|
41
|
-
intersection,
|
|
42
|
-
intersects
|
|
43
|
-
} from "./chunk-GYYHT756.mjs";
|
|
44
|
-
import {
|
|
45
|
-
fromRange
|
|
46
|
-
} from "./chunk-25JXNQDO.mjs";
|
|
47
|
-
import {
|
|
48
|
-
union
|
|
49
|
-
} from "./chunk-K4PDUEML.mjs";
|
|
50
|
-
import {
|
|
51
|
-
getElementRect
|
|
52
|
-
} from "./chunk-BDA5H4ND.mjs";
|
|
53
|
-
import {
|
|
54
|
-
getRectFromPoints
|
|
55
|
-
} from "./chunk-D46YBNP3.mjs";
|
|
56
|
-
import {
|
|
57
|
-
getRotationRect,
|
|
58
|
-
rotate,
|
|
59
|
-
toRad
|
|
60
|
-
} from "./chunk-W5IPBTYQ.mjs";
|
|
61
|
-
import {
|
|
62
|
-
createRect,
|
|
63
|
-
getRectCenters,
|
|
64
|
-
getRectCorners,
|
|
65
|
-
getRectEdges,
|
|
66
|
-
isRect
|
|
67
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
68
|
-
export {
|
|
69
|
-
alignRect,
|
|
70
|
-
closest,
|
|
71
|
-
closestSideToPoint,
|
|
72
|
-
closestSideToRect,
|
|
73
|
-
collisions,
|
|
74
|
-
contains,
|
|
75
|
-
containsPoint,
|
|
76
|
-
containsRect,
|
|
77
|
-
createRect,
|
|
78
|
-
debugPolygon,
|
|
79
|
-
distance,
|
|
80
|
-
distanceBtwEdges,
|
|
81
|
-
distanceFromPoint,
|
|
82
|
-
distanceFromRect,
|
|
83
|
-
expand,
|
|
84
|
-
fromRange,
|
|
85
|
-
getElementPolygon,
|
|
86
|
-
getElementRect,
|
|
87
|
-
getRectCenters,
|
|
88
|
-
getRectCorners,
|
|
89
|
-
getRectEdges,
|
|
90
|
-
getRectFromPoints,
|
|
91
|
-
getRotationRect,
|
|
92
|
-
getViewportRect,
|
|
93
|
-
getWindowRect,
|
|
94
|
-
inset,
|
|
95
|
-
intersection,
|
|
96
|
-
intersects,
|
|
97
|
-
isPointInPolygon,
|
|
98
|
-
isRect,
|
|
99
|
-
isSymmetric,
|
|
100
|
-
rotate,
|
|
101
|
-
shift,
|
|
102
|
-
shrink,
|
|
103
|
-
toRad,
|
|
104
|
-
union
|
|
105
|
-
};
|
|
1
|
+
export { alignRect } from './align.mjs';
|
|
2
|
+
export { closest, closestSideToPoint, closestSideToRect } from './closest.mjs';
|
|
3
|
+
export { contains, containsPoint, containsRect } from './contains.mjs';
|
|
4
|
+
export { distance, distanceBtwEdges, distanceFromPoint, distanceFromRect } from './distance.mjs';
|
|
5
|
+
export { getElementRect } from './from-element.mjs';
|
|
6
|
+
export { getRectFromPoints } from './from-points.mjs';
|
|
7
|
+
export { fromRange } from './from-range.mjs';
|
|
8
|
+
export { getRotationRect, rotate, toRad } from './from-rotation.mjs';
|
|
9
|
+
export { getViewportRect, getWindowRect } from './from-window.mjs';
|
|
10
|
+
export { getElementPolygon } from './get-polygon.mjs';
|
|
11
|
+
export { collisions, intersection, intersects } from './intersection.mjs';
|
|
12
|
+
export { expand, inset, isSymmetric, shift, shrink } from './operations.mjs';
|
|
13
|
+
export { debugPolygon, isPointInPolygon } from './polygon.mjs';
|
|
14
|
+
export { createRect, getRectCenters, getRectCorners, getRectEdges, isRect } from './rect.mjs';
|
|
15
|
+
export { union } from './union.mjs';
|
package/dist/intersection.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
import { RectSide } from
|
|
3
|
-
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { RectSide } from "./types";
|
|
4
3
|
/**
|
|
5
4
|
* Checks if a Rect intersects another Rect
|
|
6
5
|
*/
|
|
7
|
-
declare function intersects(a: Rect, b: Rect): boolean;
|
|
6
|
+
export declare function intersects(a: Rect, b: Rect): boolean;
|
|
8
7
|
/**
|
|
9
8
|
* Returns a new Rect that represents the intersection between two Rects
|
|
10
9
|
*/
|
|
11
|
-
declare function intersection(a: Rect, b: Rect): Rect;
|
|
10
|
+
export declare function intersection(a: Rect, b: Rect): Rect;
|
|
12
11
|
/**
|
|
13
12
|
* Returns whether two rects collide along each edge
|
|
14
13
|
*/
|
|
15
|
-
declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
|
16
|
-
|
|
17
|
-
export { collisions, intersection, intersects };
|
|
14
|
+
export declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
package/dist/intersection.js
CHANGED
|
@@ -1,53 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var intersection_exports = {};
|
|
22
|
-
__export(intersection_exports, {
|
|
23
|
-
collisions: () => collisions,
|
|
24
|
-
intersection: () => intersection,
|
|
25
|
-
intersects: () => intersects
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(intersection_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
var point = (x, y) => ({ x, y });
|
|
31
|
-
function createRect(r) {
|
|
32
|
-
const { x, y, width, height } = r;
|
|
33
|
-
const midX = x + width / 2;
|
|
34
|
-
const midY = y + height / 2;
|
|
35
|
-
return {
|
|
36
|
-
x,
|
|
37
|
-
y,
|
|
38
|
-
width,
|
|
39
|
-
height,
|
|
40
|
-
minX: x,
|
|
41
|
-
minY: y,
|
|
42
|
-
maxX: x + width,
|
|
43
|
-
maxY: y + height,
|
|
44
|
-
midX,
|
|
45
|
-
midY,
|
|
46
|
-
center: point(midX, midY)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
49
6
|
|
|
50
|
-
// src/intersection.ts
|
|
51
7
|
function intersects(a, b) {
|
|
52
8
|
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
53
9
|
}
|
|
@@ -56,7 +12,7 @@ function intersection(a, b) {
|
|
|
56
12
|
const y = Math.max(a.y, b.y);
|
|
57
13
|
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
58
14
|
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
59
|
-
return createRect({ x, y, width: x2 - x, height: y2 - y });
|
|
15
|
+
return rect.createRect({ x, y, width: x2 - x, height: y2 - y });
|
|
60
16
|
}
|
|
61
17
|
function collisions(a, b) {
|
|
62
18
|
return {
|
|
@@ -66,9 +22,7 @@ function collisions(a, b) {
|
|
|
66
22
|
left: a.minX <= b.minX
|
|
67
23
|
};
|
|
68
24
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
intersects
|
|
74
|
-
});
|
|
25
|
+
|
|
26
|
+
exports.collisions = collisions;
|
|
27
|
+
exports.intersection = intersection;
|
|
28
|
+
exports.intersects = intersects;
|
package/dist/intersection.mjs
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
1
|
+
import { createRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
function intersects(a, b) {
|
|
4
|
+
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
5
|
+
}
|
|
6
|
+
function intersection(a, b) {
|
|
7
|
+
const x = Math.max(a.x, b.x);
|
|
8
|
+
const y = Math.max(a.y, b.y);
|
|
9
|
+
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
10
|
+
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
11
|
+
return createRect({ x, y, width: x2 - x, height: y2 - y });
|
|
12
|
+
}
|
|
13
|
+
function collisions(a, b) {
|
|
14
|
+
return {
|
|
15
|
+
top: a.minY <= b.minY,
|
|
16
|
+
right: a.maxX >= b.maxX,
|
|
17
|
+
bottom: a.maxY >= b.maxY,
|
|
18
|
+
left: a.minX <= b.minX
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { collisions, intersection, intersects };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
8
|
-
declare function shift(r: Rect, o: Partial<Point>): Rect;
|
|
9
|
-
|
|
10
|
-
export { expand, inset, isSymmetric, shift, shrink };
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { Point, RectInset, SymmetricRectInset } from "./types";
|
|
3
|
+
export declare const isSymmetric: (v: any) => v is SymmetricRectInset;
|
|
4
|
+
export declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
|
|
5
|
+
export declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
6
|
+
export declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
7
|
+
export declare function shift(r: Rect, o: Partial<Point>): Rect;
|
package/dist/operations.js
CHANGED
|
@@ -1,60 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var operations_exports = {};
|
|
22
|
-
__export(operations_exports, {
|
|
23
|
-
expand: () => expand,
|
|
24
|
-
inset: () => inset,
|
|
25
|
-
isSymmetric: () => isSymmetric,
|
|
26
|
-
shift: () => shift,
|
|
27
|
-
shrink: () => shrink
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(operations_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
30
4
|
|
|
31
|
-
|
|
32
|
-
var point = (x, y) => ({ x, y });
|
|
33
|
-
function createRect(r) {
|
|
34
|
-
const { x, y, width, height } = r;
|
|
35
|
-
const midX = x + width / 2;
|
|
36
|
-
const midY = y + height / 2;
|
|
37
|
-
return {
|
|
38
|
-
x,
|
|
39
|
-
y,
|
|
40
|
-
width,
|
|
41
|
-
height,
|
|
42
|
-
minX: x,
|
|
43
|
-
minY: y,
|
|
44
|
-
maxX: x + width,
|
|
45
|
-
maxY: y + height,
|
|
46
|
-
midX,
|
|
47
|
-
midY,
|
|
48
|
-
center: point(midX, midY)
|
|
49
|
-
};
|
|
50
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
51
6
|
|
|
52
|
-
|
|
53
|
-
var isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
7
|
+
const isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
54
8
|
function inset(r, i) {
|
|
55
9
|
const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
|
|
56
10
|
const { top = 0, right = 0, bottom = 0, left = 0 } = v;
|
|
57
|
-
return createRect({
|
|
11
|
+
return rect.createRect({
|
|
58
12
|
x: r.x + left,
|
|
59
13
|
y: r.y + top,
|
|
60
14
|
width: r.width - left - right,
|
|
@@ -71,18 +25,16 @@ function shrink(r, v) {
|
|
|
71
25
|
}
|
|
72
26
|
function shift(r, o) {
|
|
73
27
|
const { x = 0, y = 0 } = o;
|
|
74
|
-
return createRect({
|
|
28
|
+
return rect.createRect({
|
|
75
29
|
x: r.x + x,
|
|
76
30
|
y: r.y + y,
|
|
77
31
|
width: r.width,
|
|
78
32
|
height: r.height
|
|
79
33
|
});
|
|
80
34
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
shrink
|
|
88
|
-
});
|
|
35
|
+
|
|
36
|
+
exports.expand = expand;
|
|
37
|
+
exports.inset = inset;
|
|
38
|
+
exports.isSymmetric = isSymmetric;
|
|
39
|
+
exports.shift = shift;
|
|
40
|
+
exports.shrink = shrink;
|
package/dist/operations.mjs
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
1
|
+
import { createRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
const isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
4
|
+
function inset(r, i) {
|
|
5
|
+
const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
|
|
6
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = v;
|
|
7
|
+
return createRect({
|
|
8
|
+
x: r.x + left,
|
|
9
|
+
y: r.y + top,
|
|
10
|
+
width: r.width - left - right,
|
|
11
|
+
height: r.height - top - bottom
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function expand(r, v) {
|
|
15
|
+
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
16
|
+
return inset(r, value);
|
|
17
|
+
}
|
|
18
|
+
function shrink(r, v) {
|
|
19
|
+
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
20
|
+
return inset(r, value);
|
|
21
|
+
}
|
|
22
|
+
function shift(r, o) {
|
|
23
|
+
const { x = 0, y = 0 } = o;
|
|
24
|
+
return createRect({
|
|
25
|
+
x: r.x + x,
|
|
26
|
+
y: r.y + y,
|
|
27
|
+
width: r.width,
|
|
28
|
+
height: r.height
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { expand, inset, isSymmetric, shift, shrink };
|
package/dist/polygon.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { Point } from
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function debugPolygon(polygon: Point[]): () => void;
|
|
5
|
-
|
|
6
|
-
export { debugPolygon, isPointInPolygon };
|
|
1
|
+
import type { Point } from "./types";
|
|
2
|
+
export declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
3
|
+
export declare function debugPolygon(polygon: Point[]): () => void;
|
package/dist/polygon.js
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
19
4
|
|
|
20
|
-
// src/polygon.ts
|
|
21
|
-
var polygon_exports = {};
|
|
22
|
-
__export(polygon_exports, {
|
|
23
|
-
debugPolygon: () => debugPolygon,
|
|
24
|
-
isPointInPolygon: () => isPointInPolygon
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(polygon_exports);
|
|
27
5
|
function isPointInPolygon(polygon, point) {
|
|
28
6
|
const { x, y } = point;
|
|
29
7
|
let c = false;
|
|
@@ -70,8 +48,6 @@ function debugPolygon(polygon) {
|
|
|
70
48
|
el.remove();
|
|
71
49
|
};
|
|
72
50
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
isPointInPolygon
|
|
77
|
-
});
|
|
51
|
+
|
|
52
|
+
exports.debugPolygon = debugPolygon;
|
|
53
|
+
exports.isPointInPolygon = isPointInPolygon;
|
package/dist/polygon.mjs
CHANGED
|
@@ -1,8 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
function isPointInPolygon(polygon, point) {
|
|
2
|
+
const { x, y } = point;
|
|
3
|
+
let c = false;
|
|
4
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
5
|
+
const xi = polygon[i].x;
|
|
6
|
+
const yi = polygon[i].y;
|
|
7
|
+
const xj = polygon[j].x;
|
|
8
|
+
const yj = polygon[j].y;
|
|
9
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
|
|
10
|
+
c = !c;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return c;
|
|
14
|
+
}
|
|
15
|
+
function createPolygonElement() {
|
|
16
|
+
const id = "debug-polygon";
|
|
17
|
+
const existingPolygon = document.getElementById(id);
|
|
18
|
+
if (existingPolygon) {
|
|
19
|
+
return existingPolygon;
|
|
20
|
+
}
|
|
21
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
22
|
+
Object.assign(svg.style, {
|
|
23
|
+
top: "0",
|
|
24
|
+
left: "0",
|
|
25
|
+
width: "100%",
|
|
26
|
+
height: "100%",
|
|
27
|
+
opacity: "0.15",
|
|
28
|
+
position: "fixed",
|
|
29
|
+
pointerEvents: "none",
|
|
30
|
+
fill: "red"
|
|
31
|
+
});
|
|
32
|
+
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
33
|
+
polygon.setAttribute("id", id);
|
|
34
|
+
polygon.setAttribute("points", "0,0 0,0");
|
|
35
|
+
svg.appendChild(polygon);
|
|
36
|
+
document.body.appendChild(svg);
|
|
37
|
+
return polygon;
|
|
38
|
+
}
|
|
39
|
+
function debugPolygon(polygon) {
|
|
40
|
+
const el = createPolygonElement();
|
|
41
|
+
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
42
|
+
el.setAttribute("points", points);
|
|
43
|
+
return () => {
|
|
44
|
+
el.remove();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { debugPolygon, isPointInPolygon };
|
package/dist/rect.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function createRect(r: RectValue): {
|
|
1
|
+
import type { RectEdge, RectValue } from "./types";
|
|
2
|
+
export declare function createRect(r: RectValue): {
|
|
4
3
|
x: number;
|
|
5
4
|
y: number;
|
|
6
5
|
width: number;
|
|
@@ -16,9 +15,9 @@ declare function createRect(r: RectValue): {
|
|
|
16
15
|
y: number;
|
|
17
16
|
};
|
|
18
17
|
};
|
|
19
|
-
type Rect = ReturnType<typeof createRect>;
|
|
20
|
-
declare function isRect(v: any): v is Rect;
|
|
21
|
-
declare function getRectCenters(v: Rect): {
|
|
18
|
+
export type Rect = ReturnType<typeof createRect>;
|
|
19
|
+
export declare function isRect(v: any): v is Rect;
|
|
20
|
+
export declare function getRectCenters(v: Rect): {
|
|
22
21
|
top: {
|
|
23
22
|
x: number;
|
|
24
23
|
y: number;
|
|
@@ -36,7 +35,7 @@ declare function getRectCenters(v: Rect): {
|
|
|
36
35
|
y: number;
|
|
37
36
|
};
|
|
38
37
|
};
|
|
39
|
-
declare function getRectCorners(v: Rect): {
|
|
38
|
+
export declare function getRectCorners(v: Rect): {
|
|
40
39
|
top: {
|
|
41
40
|
x: number;
|
|
42
41
|
y: number;
|
|
@@ -54,11 +53,9 @@ declare function getRectCorners(v: Rect): {
|
|
|
54
53
|
y: number;
|
|
55
54
|
};
|
|
56
55
|
};
|
|
57
|
-
declare function getRectEdges(v: Rect): {
|
|
56
|
+
export declare function getRectEdges(v: Rect): {
|
|
58
57
|
top: RectEdge;
|
|
59
58
|
right: RectEdge;
|
|
60
59
|
bottom: RectEdge;
|
|
61
60
|
left: RectEdge;
|
|
62
61
|
};
|
|
63
|
-
|
|
64
|
-
export { Rect, createRect, getRectCenters, getRectCorners, getRectEdges, isRect };
|
package/dist/rect.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
createRect: () => createRect,
|
|
24
|
-
getRectCenters: () => getRectCenters,
|
|
25
|
-
getRectCorners: () => getRectCorners,
|
|
26
|
-
getRectEdges: () => getRectEdges,
|
|
27
|
-
isRect: () => isRect
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(rect_exports);
|
|
30
|
-
var point = (x, y) => ({ x, y });
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const point = (x, y) => ({ x, y });
|
|
31
6
|
function createRect(r) {
|
|
32
7
|
const { x, y, width, height } = r;
|
|
33
8
|
const midX = x + width / 2;
|
|
@@ -46,7 +21,7 @@ function createRect(r) {
|
|
|
46
21
|
center: point(midX, midY)
|
|
47
22
|
};
|
|
48
23
|
}
|
|
49
|
-
|
|
24
|
+
const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
50
25
|
function isRect(v) {
|
|
51
26
|
return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
|
|
52
27
|
}
|
|
@@ -72,11 +47,9 @@ function getRectEdges(v) {
|
|
|
72
47
|
const left = [c.top, c.left];
|
|
73
48
|
return { top, right, bottom, left };
|
|
74
49
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
isRect
|
|
82
|
-
});
|
|
50
|
+
|
|
51
|
+
exports.createRect = createRect;
|
|
52
|
+
exports.getRectCenters = getRectCenters;
|
|
53
|
+
exports.getRectCorners = getRectCorners;
|
|
54
|
+
exports.getRectEdges = getRectEdges;
|
|
55
|
+
exports.isRect = isRect;
|