@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/polygon.mjs
CHANGED
|
@@ -1,64 +1,76 @@
|
|
|
1
|
-
// src/polygon.ts
|
|
2
1
|
import { createRect, getRectCorners } from "./rect.mjs";
|
|
2
|
+
// src/polygon.ts
|
|
3
3
|
function getElementPolygon(rectValue, placement) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const rect = createRect(rectValue);
|
|
5
|
+
const { top, right, left, bottom } = getRectCorners(rect);
|
|
6
|
+
const [base] = placement.split("-");
|
|
7
|
+
return {
|
|
8
|
+
top: [
|
|
9
|
+
left,
|
|
10
|
+
top,
|
|
11
|
+
right,
|
|
12
|
+
bottom
|
|
13
|
+
],
|
|
14
|
+
right: [
|
|
15
|
+
top,
|
|
16
|
+
right,
|
|
17
|
+
bottom,
|
|
18
|
+
left
|
|
19
|
+
],
|
|
20
|
+
bottom: [
|
|
21
|
+
top,
|
|
22
|
+
left,
|
|
23
|
+
bottom,
|
|
24
|
+
right
|
|
25
|
+
],
|
|
26
|
+
left: [
|
|
27
|
+
right,
|
|
28
|
+
top,
|
|
29
|
+
left,
|
|
30
|
+
bottom
|
|
31
|
+
]
|
|
32
|
+
}[base];
|
|
13
33
|
}
|
|
14
34
|
function isPointInPolygon(polygon, point) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return c;
|
|
35
|
+
const { x, y } = point;
|
|
36
|
+
let c = false;
|
|
37
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
38
|
+
const xi = polygon[i].x;
|
|
39
|
+
const yi = polygon[i].y;
|
|
40
|
+
const xj = polygon[j].x;
|
|
41
|
+
const yj = polygon[j].y;
|
|
42
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) c = !c;
|
|
43
|
+
}
|
|
44
|
+
return c;
|
|
27
45
|
}
|
|
28
46
|
function createPolygonElement() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
document.body.appendChild(svg);
|
|
50
|
-
return polygon;
|
|
47
|
+
const id = "debug-polygon";
|
|
48
|
+
const existingPolygon = document.getElementById(id);
|
|
49
|
+
if (existingPolygon) return existingPolygon;
|
|
50
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
51
|
+
Object.assign(svg.style, {
|
|
52
|
+
top: "0",
|
|
53
|
+
left: "0",
|
|
54
|
+
width: "100%",
|
|
55
|
+
height: "100%",
|
|
56
|
+
opacity: "0.15",
|
|
57
|
+
position: "fixed",
|
|
58
|
+
pointerEvents: "none",
|
|
59
|
+
fill: "red"
|
|
60
|
+
});
|
|
61
|
+
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
62
|
+
polygon.setAttribute("id", id);
|
|
63
|
+
polygon.setAttribute("points", "0,0 0,0");
|
|
64
|
+
svg.appendChild(polygon);
|
|
65
|
+
document.body.appendChild(svg);
|
|
66
|
+
return polygon;
|
|
51
67
|
}
|
|
52
68
|
function debugPolygon(polygon) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
const el = createPolygonElement();
|
|
70
|
+
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
71
|
+
el.setAttribute("points", points);
|
|
72
|
+
return () => {
|
|
73
|
+
el.remove();
|
|
74
|
+
};
|
|
59
75
|
}
|
|
60
|
-
export {
|
|
61
|
-
debugPolygon,
|
|
62
|
-
getElementPolygon,
|
|
63
|
-
isPointInPolygon
|
|
64
|
-
};
|
|
76
|
+
export { debugPolygon, getElementPolygon, isPointInPolygon };
|
package/dist/rect.d.mts
CHANGED
|
@@ -1,65 +1,62 @@
|
|
|
1
|
-
import { Point,
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
|
|
1
|
+
import { Point, Rect, RectEdge, RectInit, Size } from "./types.mjs";
|
|
2
|
+
export declare const ZERO_POINT: Point;
|
|
3
|
+
export declare const createPoint: (x: number, y: number) => {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const subtractPoints: (a: Point, b: Point | null) => Point;
|
|
8
|
+
export declare const addPoints: (a: Point, b: Point) => {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const getMidpoint: (a: Point, b: Point, offset?: Point) => Point;
|
|
13
|
+
export declare function isPoint(v: any): v is Point;
|
|
14
|
+
export declare function createRect(r: RectInit): Rect;
|
|
15
|
+
export declare function isRect(v: any): v is Rect;
|
|
16
|
+
export declare function getRectCenters(v: Rect): {
|
|
17
|
+
top: {
|
|
5
18
|
x: number;
|
|
6
19
|
y: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
declare const addPoints: (a: Point, b: Point) => {
|
|
20
|
+
};
|
|
21
|
+
right: {
|
|
10
22
|
x: number;
|
|
11
23
|
y: number;
|
|
24
|
+
};
|
|
25
|
+
bottom: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
};
|
|
29
|
+
left: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
12
33
|
};
|
|
13
|
-
declare
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
left: {
|
|
31
|
-
x: number;
|
|
32
|
-
y: number;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
declare function getRectCorners(v: Rect): {
|
|
36
|
-
top: {
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
|
-
};
|
|
40
|
-
right: {
|
|
41
|
-
x: number;
|
|
42
|
-
y: number;
|
|
43
|
-
};
|
|
44
|
-
bottom: {
|
|
45
|
-
x: number;
|
|
46
|
-
y: number;
|
|
47
|
-
};
|
|
48
|
-
left: {
|
|
49
|
-
x: number;
|
|
50
|
-
y: number;
|
|
51
|
-
};
|
|
34
|
+
export declare function getRectCorners(v: Rect): {
|
|
35
|
+
top: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
39
|
+
right: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
};
|
|
43
|
+
bottom: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
47
|
+
left: {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
};
|
|
52
51
|
};
|
|
53
|
-
declare function getRectEdges(v: Rect): {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
export declare function getRectEdges(v: Rect): {
|
|
53
|
+
top: RectEdge;
|
|
54
|
+
right: RectEdge;
|
|
55
|
+
bottom: RectEdge;
|
|
56
|
+
left: RectEdge;
|
|
58
57
|
};
|
|
59
|
-
declare const getCenterPoint: (rect: RectInit) => Point;
|
|
60
|
-
declare const isVisibleSize: (size: Size) => boolean;
|
|
61
|
-
declare const scaleSize: (size: Size, factor: number) => Size;
|
|
62
|
-
declare const scaleRect: (rect: RectInit, scale: Point) => RectInit;
|
|
63
|
-
declare const roundRect: (rect: RectInit) => RectInit;
|
|
64
|
-
|
|
65
|
-
export { ZERO_POINT, addPoints, createPoint, createRect, getCenterPoint, getMidpoint, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, isVisibleSize, roundRect, scaleRect, scaleSize, subtractPoints };
|
|
58
|
+
export declare const getCenterPoint: (rect: RectInit) => Point;
|
|
59
|
+
export declare const isVisibleSize: (size: Size) => boolean;
|
|
60
|
+
export declare const scaleSize: (size: Size, factor: number) => Size;
|
|
61
|
+
export declare const scaleRect: (rect: RectInit, scale: Point) => RectInit;
|
|
62
|
+
export declare const roundRect: (rect: RectInit) => RectInit;
|
package/dist/rect.d.ts
CHANGED
|
@@ -1,65 +1,62 @@
|
|
|
1
|
-
import { Point,
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
|
|
1
|
+
import { Point, Rect, RectEdge, RectInit, Size } from "./types.js";
|
|
2
|
+
export declare const ZERO_POINT: Point;
|
|
3
|
+
export declare const createPoint: (x: number, y: number) => {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const subtractPoints: (a: Point, b: Point | null) => Point;
|
|
8
|
+
export declare const addPoints: (a: Point, b: Point) => {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const getMidpoint: (a: Point, b: Point, offset?: Point) => Point;
|
|
13
|
+
export declare function isPoint(v: any): v is Point;
|
|
14
|
+
export declare function createRect(r: RectInit): Rect;
|
|
15
|
+
export declare function isRect(v: any): v is Rect;
|
|
16
|
+
export declare function getRectCenters(v: Rect): {
|
|
17
|
+
top: {
|
|
5
18
|
x: number;
|
|
6
19
|
y: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
declare const addPoints: (a: Point, b: Point) => {
|
|
20
|
+
};
|
|
21
|
+
right: {
|
|
10
22
|
x: number;
|
|
11
23
|
y: number;
|
|
24
|
+
};
|
|
25
|
+
bottom: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
};
|
|
29
|
+
left: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
12
33
|
};
|
|
13
|
-
declare
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
left: {
|
|
31
|
-
x: number;
|
|
32
|
-
y: number;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
declare function getRectCorners(v: Rect): {
|
|
36
|
-
top: {
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
|
-
};
|
|
40
|
-
right: {
|
|
41
|
-
x: number;
|
|
42
|
-
y: number;
|
|
43
|
-
};
|
|
44
|
-
bottom: {
|
|
45
|
-
x: number;
|
|
46
|
-
y: number;
|
|
47
|
-
};
|
|
48
|
-
left: {
|
|
49
|
-
x: number;
|
|
50
|
-
y: number;
|
|
51
|
-
};
|
|
34
|
+
export declare function getRectCorners(v: Rect): {
|
|
35
|
+
top: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
39
|
+
right: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
};
|
|
43
|
+
bottom: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
47
|
+
left: {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
};
|
|
52
51
|
};
|
|
53
|
-
declare function getRectEdges(v: Rect): {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
export declare function getRectEdges(v: Rect): {
|
|
53
|
+
top: RectEdge;
|
|
54
|
+
right: RectEdge;
|
|
55
|
+
bottom: RectEdge;
|
|
56
|
+
left: RectEdge;
|
|
58
57
|
};
|
|
59
|
-
declare const getCenterPoint: (rect: RectInit) => Point;
|
|
60
|
-
declare const isVisibleSize: (size: Size) => boolean;
|
|
61
|
-
declare const scaleSize: (size: Size, factor: number) => Size;
|
|
62
|
-
declare const scaleRect: (rect: RectInit, scale: Point) => RectInit;
|
|
63
|
-
declare const roundRect: (rect: RectInit) => RectInit;
|
|
64
|
-
|
|
65
|
-
export { ZERO_POINT, addPoints, createPoint, createRect, getCenterPoint, getMidpoint, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, isVisibleSize, roundRect, scaleRect, scaleSize, subtractPoints };
|
|
58
|
+
export declare const getCenterPoint: (rect: RectInit) => Point;
|
|
59
|
+
export declare const isVisibleSize: (size: Size) => boolean;
|
|
60
|
+
export declare const scaleSize: (size: Size, factor: number) => Size;
|
|
61
|
+
export declare const scaleRect: (rect: RectInit, scale: Point) => RectInit;
|
|
62
|
+
export declare const roundRect: (rect: RectInit) => RectInit;
|
package/dist/rect.js
CHANGED
|
@@ -1,137 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
20
5
|
// src/rect.ts
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
addPoints: () => addPoints,
|
|
25
|
-
createPoint: () => createPoint,
|
|
26
|
-
createRect: () => createRect,
|
|
27
|
-
getCenterPoint: () => getCenterPoint,
|
|
28
|
-
getMidpoint: () => getMidpoint,
|
|
29
|
-
getRectCenters: () => getRectCenters,
|
|
30
|
-
getRectCorners: () => getRectCorners,
|
|
31
|
-
getRectEdges: () => getRectEdges,
|
|
32
|
-
isPoint: () => isPoint,
|
|
33
|
-
isRect: () => isRect,
|
|
34
|
-
isVisibleSize: () => isVisibleSize,
|
|
35
|
-
roundRect: () => roundRect,
|
|
36
|
-
scaleRect: () => scaleRect,
|
|
37
|
-
scaleSize: () => scaleSize,
|
|
38
|
-
subtractPoints: () => subtractPoints
|
|
6
|
+
const ZERO_POINT = Object.freeze({
|
|
7
|
+
x: 0,
|
|
8
|
+
y: 0
|
|
39
9
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
10
|
+
const createPoint = (x, y) => ({
|
|
11
|
+
x,
|
|
12
|
+
y
|
|
13
|
+
});
|
|
14
|
+
const subtractPoints = (a, b) => {
|
|
15
|
+
if (!b) return a;
|
|
16
|
+
return createPoint(a.x - b.x, a.y - b.y);
|
|
46
17
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
const addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
|
|
19
|
+
const getMidpoint = (a, b, offset) => ({
|
|
20
|
+
x: (a.x + b.x) / 2 - (offset?.x ?? 0),
|
|
21
|
+
y: (a.y + b.y) / 2 - (offset?.y ?? 0)
|
|
51
22
|
});
|
|
52
23
|
function isPoint(v) {
|
|
53
|
-
|
|
24
|
+
return Reflect.has(v, "x") && Reflect.has(v, "y");
|
|
54
25
|
}
|
|
55
26
|
function createRect(r) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
27
|
+
const { x, y, width, height } = r;
|
|
28
|
+
const midX = x + width / 2;
|
|
29
|
+
const midY = y + height / 2;
|
|
30
|
+
return {
|
|
31
|
+
x,
|
|
32
|
+
y,
|
|
33
|
+
width,
|
|
34
|
+
height,
|
|
35
|
+
minX: x,
|
|
36
|
+
minY: y,
|
|
37
|
+
maxX: x + width,
|
|
38
|
+
maxY: y + height,
|
|
39
|
+
midX,
|
|
40
|
+
midY,
|
|
41
|
+
center: createPoint(midX, midY)
|
|
42
|
+
};
|
|
72
43
|
}
|
|
73
44
|
function isRect(v) {
|
|
74
|
-
|
|
45
|
+
return Reflect.has(v, "x") && Reflect.has(v, "y") && Reflect.has(v, "width") && Reflect.has(v, "height");
|
|
75
46
|
}
|
|
76
47
|
function getRectCenters(v) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
48
|
+
return {
|
|
49
|
+
top: createPoint(v.midX, v.minY),
|
|
50
|
+
right: createPoint(v.maxX, v.midY),
|
|
51
|
+
bottom: createPoint(v.midX, v.maxY),
|
|
52
|
+
left: createPoint(v.minX, v.midY)
|
|
53
|
+
};
|
|
82
54
|
}
|
|
83
55
|
function getRectCorners(v) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
56
|
+
return {
|
|
57
|
+
top: createPoint(v.minX, v.minY),
|
|
58
|
+
right: createPoint(v.maxX, v.minY),
|
|
59
|
+
bottom: createPoint(v.maxX, v.maxY),
|
|
60
|
+
left: createPoint(v.minX, v.maxY)
|
|
61
|
+
};
|
|
89
62
|
}
|
|
90
63
|
function getRectEdges(v) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
64
|
+
const c = getRectCorners(v);
|
|
65
|
+
return {
|
|
66
|
+
top: [c.top, c.right],
|
|
67
|
+
right: [c.right, c.bottom],
|
|
68
|
+
bottom: [c.left, c.bottom],
|
|
69
|
+
left: [c.top, c.left]
|
|
70
|
+
};
|
|
97
71
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
var isVisibleSize = (size) => size.width > 0 && size.height > 0;
|
|
103
|
-
var scaleSize = (size, factor) => ({
|
|
104
|
-
width: size.width * factor,
|
|
105
|
-
height: size.height * factor
|
|
72
|
+
const getCenterPoint = (rect) => ({
|
|
73
|
+
x: rect.x + rect.width / 2,
|
|
74
|
+
y: rect.y + rect.height / 2
|
|
106
75
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
height: rect.height * scale.y
|
|
76
|
+
const isVisibleSize = (size) => size.width > 0 && size.height > 0;
|
|
77
|
+
const scaleSize = (size, factor) => ({
|
|
78
|
+
width: size.width * factor,
|
|
79
|
+
height: size.height * factor
|
|
112
80
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
81
|
+
const scaleRect = (rect, scale) => ({
|
|
82
|
+
x: rect.x * scale.x,
|
|
83
|
+
y: rect.y * scale.y,
|
|
84
|
+
width: rect.width * scale.x,
|
|
85
|
+
height: rect.height * scale.y
|
|
118
86
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
createRect,
|
|
125
|
-
getCenterPoint,
|
|
126
|
-
getMidpoint,
|
|
127
|
-
getRectCenters,
|
|
128
|
-
getRectCorners,
|
|
129
|
-
getRectEdges,
|
|
130
|
-
isPoint,
|
|
131
|
-
isRect,
|
|
132
|
-
isVisibleSize,
|
|
133
|
-
roundRect,
|
|
134
|
-
scaleRect,
|
|
135
|
-
scaleSize,
|
|
136
|
-
subtractPoints
|
|
87
|
+
const roundRect = (rect) => ({
|
|
88
|
+
x: Math.round(rect.x),
|
|
89
|
+
y: Math.round(rect.y),
|
|
90
|
+
width: Math.round(rect.width),
|
|
91
|
+
height: Math.round(rect.height)
|
|
137
92
|
});
|
|
93
|
+
exports.ZERO_POINT = ZERO_POINT;
|
|
94
|
+
exports.addPoints = addPoints;
|
|
95
|
+
exports.createPoint = createPoint;
|
|
96
|
+
exports.createRect = createRect;
|
|
97
|
+
exports.getCenterPoint = getCenterPoint;
|
|
98
|
+
exports.getMidpoint = getMidpoint;
|
|
99
|
+
exports.getRectCenters = getRectCenters;
|
|
100
|
+
exports.getRectCorners = getRectCorners;
|
|
101
|
+
exports.getRectEdges = getRectEdges;
|
|
102
|
+
exports.isPoint = isPoint;
|
|
103
|
+
exports.isRect = isRect;
|
|
104
|
+
exports.isVisibleSize = isVisibleSize;
|
|
105
|
+
exports.roundRect = roundRect;
|
|
106
|
+
exports.scaleRect = scaleRect;
|
|
107
|
+
exports.scaleSize = scaleSize;
|
|
108
|
+
exports.subtractPoints = subtractPoints;
|