@zag-js/rect-utils 2.0.0-next.3 → 2.0.0-next.4
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.mts +2 -5
- package/dist/align.d.ts +2 -5
- package/dist/align.js +27 -44
- package/dist/align.mjs +23 -19
- package/dist/angle.d.mts +2 -5
- package/dist/angle.d.ts +2 -5
- package/dist/angle.js +8 -32
- package/dist/angle.mjs +4 -7
- package/dist/clamp.d.mts +8 -11
- package/dist/clamp.d.ts +8 -11
- package/dist/clamp.js +23 -46
- package/dist/clamp.mjs +18 -20
- package/dist/closest.d.mts +4 -7
- package/dist/closest.d.ts +4 -7
- package/dist/closest.js +35 -62
- package/dist/closest.mjs +29 -35
- package/dist/compass.d.mts +1 -3
- package/dist/compass.d.ts +1 -3
- package/dist/compass.js +4 -18
- package/dist/compass.mjs +1 -0
- package/dist/constrain.d.mts +2 -5
- package/dist/constrain.d.ts +2 -5
- package/dist/constrain.js +12 -37
- package/dist/constrain.mjs +8 -12
- package/dist/contains.d.mts +4 -7
- package/dist/contains.d.ts +4 -7
- package/dist/contains.js +11 -36
- package/dist/contains.mjs +5 -9
- package/dist/distance.d.mts +7 -10
- package/dist/distance.d.ts +7 -10
- package/dist/distance.js +55 -60
- package/dist/distance.mjs +48 -32
- package/dist/equality.d.mts +4 -7
- package/dist/equality.d.ts +4 -7
- package/dist/equality.js +13 -38
- package/dist/equality.mjs +7 -11
- package/dist/from-element.d.mts +12 -15
- package/dist/from-element.d.ts +12 -15
- package/dist/from-element.js +39 -58
- package/dist/from-element.mjs +35 -33
- package/dist/from-points.d.mts +2 -5
- package/dist/from-points.d.ts +2 -5
- package/dist/from-points.js +18 -36
- package/dist/from-points.mjs +14 -11
- package/dist/from-range.d.mts +2 -5
- package/dist/from-range.d.ts +2 -5
- package/dist/from-range.js +25 -46
- package/dist/from-range.mjs +19 -19
- package/dist/from-rotation.d.mts +4 -7
- package/dist/from-rotation.d.ts +4 -7
- package/dist/from-rotation.js +31 -56
- package/dist/from-rotation.mjs +25 -29
- package/dist/from-window.d.mts +13 -16
- package/dist/from-window.d.ts +13 -16
- package/dist/from-window.js +29 -44
- package/dist/from-window.mjs +24 -18
- package/dist/index.d.mts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js +91 -61
- package/dist/index.mjs +20 -21
- package/dist/interact.d.mts +34 -37
- package/dist/interact.d.ts +34 -37
- package/dist/interact.js +414 -350
- package/dist/interact.mjs +396 -311
- package/dist/intersection.d.mts +4 -7
- package/dist/intersection.d.ts +4 -7
- package/dist/intersection.js +34 -45
- package/dist/intersection.mjs +28 -18
- package/dist/operations.d.mts +6 -9
- package/dist/operations.d.ts +6 -9
- package/dist/operations.js +38 -57
- package/dist/operations.mjs +30 -28
- package/dist/polygon.d.mts +6 -9
- package/dist/polygon.d.ts +6 -9
- package/dist/polygon.js +73 -82
- package/dist/polygon.mjs +67 -55
- package/dist/rect.d.mts +55 -58
- package/dist/rect.d.ts +55 -58
- package/dist/rect.js +88 -117
- package/dist/rect.mjs +70 -78
- package/dist/types.d.mts +42 -46
- package/dist/types.d.ts +42 -46
- package/dist/types.js +4 -18
- package/dist/types.mjs +1 -0
- package/dist/union.d.mts +2 -5
- package/dist/union.d.ts +2 -5
- package/dist/union.js +16 -39
- package/dist/union.mjs +12 -14
- package/package.json +2 -2
package/dist/intersection.d.mts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { Rect, RectSide } from
|
|
2
|
-
|
|
1
|
+
import { Rect, RectSide } from "./types.mjs";
|
|
3
2
|
/**
|
|
4
3
|
* Checks if a Rect intersects another Rect
|
|
5
4
|
*/
|
|
6
|
-
declare function intersects(a: Rect, b: Rect): boolean;
|
|
5
|
+
export declare function intersects(a: Rect, b: Rect): boolean;
|
|
7
6
|
/**
|
|
8
7
|
* Returns a new Rect that represents the intersection between two Rects
|
|
9
8
|
*/
|
|
10
|
-
declare function intersection(a: Rect, b: Rect): Rect;
|
|
9
|
+
export declare function intersection(a: Rect, b: Rect): Rect;
|
|
11
10
|
/**
|
|
12
11
|
* Returns whether two rects collide along each edge
|
|
13
12
|
*/
|
|
14
|
-
declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
|
15
|
-
|
|
16
|
-
export { collisions, intersection, intersects };
|
|
13
|
+
export declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
package/dist/intersection.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { Rect, RectSide } from
|
|
2
|
-
|
|
1
|
+
import { Rect, RectSide } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Checks if a Rect intersects another Rect
|
|
5
4
|
*/
|
|
6
|
-
declare function intersects(a: Rect, b: Rect): boolean;
|
|
5
|
+
export declare function intersects(a: Rect, b: Rect): boolean;
|
|
7
6
|
/**
|
|
8
7
|
* Returns a new Rect that represents the intersection between two Rects
|
|
9
8
|
*/
|
|
10
|
-
declare function intersection(a: Rect, b: Rect): Rect;
|
|
9
|
+
export declare function intersection(a: Rect, b: Rect): Rect;
|
|
11
10
|
/**
|
|
12
11
|
* Returns whether two rects collide along each edge
|
|
13
12
|
*/
|
|
14
|
-
declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
|
15
|
-
|
|
16
|
-
export { collisions, intersection, intersects };
|
|
13
|
+
export declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
package/dist/intersection.js
CHANGED
|
@@ -1,52 +1,41 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/intersection.ts
|
|
21
|
-
var intersection_exports = {};
|
|
22
|
-
__export(intersection_exports, {
|
|
23
|
-
collisions: () => collisions,
|
|
24
|
-
intersection: () => intersection,
|
|
25
|
-
intersects: () => intersects
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
4
|
});
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/intersection.ts
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a Rect intersects another Rect
|
|
9
|
+
*/
|
|
29
10
|
function intersects(a, b) {
|
|
30
|
-
|
|
11
|
+
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
31
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns a new Rect that represents the intersection between two Rects
|
|
15
|
+
*/
|
|
32
16
|
function intersection(a, b) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
const x = Math.max(a.x, b.x);
|
|
18
|
+
const y = Math.max(a.y, b.y);
|
|
19
|
+
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
20
|
+
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
21
|
+
return require_rect.createRect({
|
|
22
|
+
x,
|
|
23
|
+
y,
|
|
24
|
+
width: x2 - x,
|
|
25
|
+
height: y2 - y
|
|
26
|
+
});
|
|
38
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns whether two rects collide along each edge
|
|
30
|
+
*/
|
|
39
31
|
function collisions(a, b) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
return {
|
|
33
|
+
top: a.minY <= b.minY,
|
|
34
|
+
right: a.maxX >= b.maxX,
|
|
35
|
+
bottom: a.maxY >= b.maxY,
|
|
36
|
+
left: a.minX <= b.minX
|
|
37
|
+
};
|
|
46
38
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
intersection,
|
|
51
|
-
intersects
|
|
52
|
-
});
|
|
39
|
+
exports.collisions = collisions;
|
|
40
|
+
exports.intersection = intersection;
|
|
41
|
+
exports.intersects = intersects;
|
package/dist/intersection.mjs
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
// src/intersection.ts
|
|
2
1
|
import { createRect } from "./rect.mjs";
|
|
2
|
+
// src/intersection.ts
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a Rect intersects another Rect
|
|
5
|
+
*/
|
|
3
6
|
function intersects(a, b) {
|
|
4
|
-
|
|
7
|
+
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns a new Rect that represents the intersection between two Rects
|
|
11
|
+
*/
|
|
6
12
|
function intersection(a, b) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
const x = Math.max(a.x, b.x);
|
|
14
|
+
const y = Math.max(a.y, b.y);
|
|
15
|
+
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
16
|
+
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
17
|
+
return createRect({
|
|
18
|
+
x,
|
|
19
|
+
y,
|
|
20
|
+
width: x2 - x,
|
|
21
|
+
height: y2 - y
|
|
22
|
+
});
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns whether two rects collide along each edge
|
|
26
|
+
*/
|
|
13
27
|
function collisions(a, b) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
return {
|
|
29
|
+
top: a.minY <= b.minY,
|
|
30
|
+
right: a.maxX >= b.maxX,
|
|
31
|
+
bottom: a.maxY >= b.maxY,
|
|
32
|
+
left: a.minX <= b.minX
|
|
33
|
+
};
|
|
20
34
|
}
|
|
21
|
-
export {
|
|
22
|
-
collisions,
|
|
23
|
-
intersection,
|
|
24
|
-
intersects
|
|
25
|
-
};
|
|
35
|
+
export { collisions, intersection, intersects };
|
package/dist/operations.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function shift(r: Rect, o: Partial<Point>): Rect;
|
|
8
|
-
|
|
9
|
-
export { expand, inset, isSymmetric, shift, shrink };
|
|
1
|
+
import { Point, Rect, RectInset, SymmetricRectInset } from "./types.mjs";
|
|
2
|
+
export declare const isSymmetric: (v: any) => v is SymmetricRectInset;
|
|
3
|
+
export declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
|
|
4
|
+
export declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
5
|
+
export declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
6
|
+
export declare function shift(r: Rect, o: Partial<Point>): Rect;
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function shift(r: Rect, o: Partial<Point>): Rect;
|
|
8
|
-
|
|
9
|
-
export { expand, inset, isSymmetric, shift, shrink };
|
|
1
|
+
import { Point, Rect, RectInset, SymmetricRectInset } from "./types.js";
|
|
2
|
+
export declare const isSymmetric: (v: any) => v is SymmetricRectInset;
|
|
3
|
+
export declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
|
|
4
|
+
export declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
5
|
+
export declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
6
|
+
export declare function shift(r: Rect, o: Partial<Point>): Rect;
|
package/dist/operations.js
CHANGED
|
@@ -1,66 +1,47 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/operations.ts
|
|
21
|
-
var operations_exports = {};
|
|
22
|
-
__export(operations_exports, {
|
|
23
|
-
expand: () => expand,
|
|
24
|
-
inset: () => inset,
|
|
25
|
-
isSymmetric: () => isSymmetric,
|
|
26
|
-
shift: () => shift,
|
|
27
|
-
shrink: () => shrink
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
28
4
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/operations.ts
|
|
7
|
+
const isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
32
8
|
function inset(r, i) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
9
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = isSymmetric(i) ? {
|
|
10
|
+
left: i.dx,
|
|
11
|
+
right: i.dx,
|
|
12
|
+
top: i.dy,
|
|
13
|
+
bottom: i.dy
|
|
14
|
+
} : i;
|
|
15
|
+
return require_rect.createRect({
|
|
16
|
+
x: r.x + left,
|
|
17
|
+
y: r.y + top,
|
|
18
|
+
width: r.width - left - right,
|
|
19
|
+
height: r.height - top - bottom
|
|
20
|
+
});
|
|
41
21
|
}
|
|
42
22
|
function expand(r, v) {
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
return inset(r, typeof v === "number" ? {
|
|
24
|
+
dx: -v,
|
|
25
|
+
dy: -v
|
|
26
|
+
} : v);
|
|
45
27
|
}
|
|
46
28
|
function shrink(r, v) {
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
return inset(r, typeof v === "number" ? {
|
|
30
|
+
dx: -v,
|
|
31
|
+
dy: -v
|
|
32
|
+
} : v);
|
|
49
33
|
}
|
|
50
34
|
function shift(r, o) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
35
|
+
const { x = 0, y = 0 } = o;
|
|
36
|
+
return require_rect.createRect({
|
|
37
|
+
x: r.x + x,
|
|
38
|
+
y: r.y + y,
|
|
39
|
+
width: r.width,
|
|
40
|
+
height: r.height
|
|
41
|
+
});
|
|
58
42
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
shift,
|
|
65
|
-
shrink
|
|
66
|
-
});
|
|
43
|
+
exports.expand = expand;
|
|
44
|
+
exports.inset = inset;
|
|
45
|
+
exports.isSymmetric = isSymmetric;
|
|
46
|
+
exports.shift = shift;
|
|
47
|
+
exports.shrink = shrink;
|
package/dist/operations.mjs
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
// src/operations.ts
|
|
2
1
|
import { createRect } from "./rect.mjs";
|
|
3
|
-
|
|
2
|
+
// src/operations.ts
|
|
3
|
+
const isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
4
4
|
function inset(r, i) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = isSymmetric(i) ? {
|
|
6
|
+
left: i.dx,
|
|
7
|
+
right: i.dx,
|
|
8
|
+
top: i.dy,
|
|
9
|
+
bottom: i.dy
|
|
10
|
+
} : i;
|
|
11
|
+
return createRect({
|
|
12
|
+
x: r.x + left,
|
|
13
|
+
y: r.y + top,
|
|
14
|
+
width: r.width - left - right,
|
|
15
|
+
height: r.height - top - bottom
|
|
16
|
+
});
|
|
13
17
|
}
|
|
14
18
|
function expand(r, v) {
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
return inset(r, typeof v === "number" ? {
|
|
20
|
+
dx: -v,
|
|
21
|
+
dy: -v
|
|
22
|
+
} : v);
|
|
17
23
|
}
|
|
18
24
|
function shrink(r, v) {
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
return inset(r, typeof v === "number" ? {
|
|
26
|
+
dx: -v,
|
|
27
|
+
dy: -v
|
|
28
|
+
} : v);
|
|
21
29
|
}
|
|
22
30
|
function shift(r, o) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
const { x = 0, y = 0 } = o;
|
|
32
|
+
return createRect({
|
|
33
|
+
x: r.x + x,
|
|
34
|
+
y: r.y + y,
|
|
35
|
+
width: r.width,
|
|
36
|
+
height: r.height
|
|
37
|
+
});
|
|
30
38
|
}
|
|
31
|
-
export {
|
|
32
|
-
expand,
|
|
33
|
-
inset,
|
|
34
|
-
isSymmetric,
|
|
35
|
-
shift,
|
|
36
|
-
shrink
|
|
37
|
-
};
|
|
39
|
+
export { expand, inset, isSymmetric, shift, shrink };
|
package/dist/polygon.d.mts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { Point, RectInit } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
1
|
+
import { Point, RectInit } from "./types.mjs";
|
|
2
|
+
export declare function getElementPolygon(rectValue: RectInit, placement: string): {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
6
5
|
}[] | undefined;
|
|
7
|
-
declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
8
|
-
declare function debugPolygon(polygon: Point[]): () => void;
|
|
9
|
-
|
|
10
|
-
export { debugPolygon, getElementPolygon, isPointInPolygon };
|
|
6
|
+
export declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
7
|
+
export declare function debugPolygon(polygon: Point[]): () => void;
|
package/dist/polygon.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { Point, RectInit } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
1
|
+
import { Point, RectInit } from "./types.js";
|
|
2
|
+
export declare function getElementPolygon(rectValue: RectInit, placement: string): {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
6
5
|
}[] | undefined;
|
|
7
|
-
declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
8
|
-
declare function debugPolygon(polygon: Point[]): () => void;
|
|
9
|
-
|
|
10
|
-
export { debugPolygon, getElementPolygon, isPointInPolygon };
|
|
6
|
+
export declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
7
|
+
export declare function debugPolygon(polygon: Point[]): () => void;
|
package/dist/polygon.js
CHANGED
|
@@ -1,91 +1,82 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/polygon.ts
|
|
21
|
-
var polygon_exports = {};
|
|
22
|
-
__export(polygon_exports, {
|
|
23
|
-
debugPolygon: () => debugPolygon,
|
|
24
|
-
getElementPolygon: () => getElementPolygon,
|
|
25
|
-
isPointInPolygon: () => isPointInPolygon
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
4
|
});
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/polygon.ts
|
|
29
7
|
function getElementPolygon(rectValue, placement) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
const rect = require_rect.createRect(rectValue);
|
|
9
|
+
const { top, right, left, bottom } = require_rect.getRectCorners(rect);
|
|
10
|
+
const [base] = placement.split("-");
|
|
11
|
+
return {
|
|
12
|
+
top: [
|
|
13
|
+
left,
|
|
14
|
+
top,
|
|
15
|
+
right,
|
|
16
|
+
bottom
|
|
17
|
+
],
|
|
18
|
+
right: [
|
|
19
|
+
top,
|
|
20
|
+
right,
|
|
21
|
+
bottom,
|
|
22
|
+
left
|
|
23
|
+
],
|
|
24
|
+
bottom: [
|
|
25
|
+
top,
|
|
26
|
+
left,
|
|
27
|
+
bottom,
|
|
28
|
+
right
|
|
29
|
+
],
|
|
30
|
+
left: [
|
|
31
|
+
right,
|
|
32
|
+
top,
|
|
33
|
+
left,
|
|
34
|
+
bottom
|
|
35
|
+
]
|
|
36
|
+
}[base];
|
|
39
37
|
}
|
|
40
38
|
function isPointInPolygon(polygon, point) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return c;
|
|
39
|
+
const { x, y } = point;
|
|
40
|
+
let c = false;
|
|
41
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
42
|
+
const xi = polygon[i].x;
|
|
43
|
+
const yi = polygon[i].y;
|
|
44
|
+
const xj = polygon[j].x;
|
|
45
|
+
const yj = polygon[j].y;
|
|
46
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) c = !c;
|
|
47
|
+
}
|
|
48
|
+
return c;
|
|
53
49
|
}
|
|
54
50
|
function createPolygonElement() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
document.body.appendChild(svg);
|
|
76
|
-
return polygon;
|
|
51
|
+
const id = "debug-polygon";
|
|
52
|
+
const existingPolygon = document.getElementById(id);
|
|
53
|
+
if (existingPolygon) return existingPolygon;
|
|
54
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
55
|
+
Object.assign(svg.style, {
|
|
56
|
+
top: "0",
|
|
57
|
+
left: "0",
|
|
58
|
+
width: "100%",
|
|
59
|
+
height: "100%",
|
|
60
|
+
opacity: "0.15",
|
|
61
|
+
position: "fixed",
|
|
62
|
+
pointerEvents: "none",
|
|
63
|
+
fill: "red"
|
|
64
|
+
});
|
|
65
|
+
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
66
|
+
polygon.setAttribute("id", id);
|
|
67
|
+
polygon.setAttribute("points", "0,0 0,0");
|
|
68
|
+
svg.appendChild(polygon);
|
|
69
|
+
document.body.appendChild(svg);
|
|
70
|
+
return polygon;
|
|
77
71
|
}
|
|
78
72
|
function debugPolygon(polygon) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
const el = createPolygonElement();
|
|
74
|
+
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
75
|
+
el.setAttribute("points", points);
|
|
76
|
+
return () => {
|
|
77
|
+
el.remove();
|
|
78
|
+
};
|
|
85
79
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
getElementPolygon,
|
|
90
|
-
isPointInPolygon
|
|
91
|
-
});
|
|
80
|
+
exports.debugPolygon = debugPolygon;
|
|
81
|
+
exports.getElementPolygon = getElementPolygon;
|
|
82
|
+
exports.isPointInPolygon = isPointInPolygon;
|