@tscircuit/math-utils 0.0.31 → 0.0.33
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/chunk-3WCUPG5S.js +10 -0
- package/dist/chunk-3WCUPG5S.js.map +1 -0
- package/dist/{chunk-RCZE5Q5V.js → chunk-6K6N6UTQ.js} +2 -1
- package/dist/chunk-6K6N6UTQ.js.map +1 -0
- package/dist/get-bounds-center.d.ts +10 -0
- package/dist/get-bounds-center.js +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -7
- package/dist/polygon.d.ts +2 -1
- package/dist/polygon.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-RCZE5Q5V.js.map +0 -1
- package/dist/chunk-TDJ6LMXM.js +0 -9
- package/dist/chunk-TDJ6LMXM.js.map +0 -1
- package/dist/is-point-in-bounds.d.ts +0 -11
- package/dist/is-point-in-bounds.js +0 -7
- /package/dist/{is-point-in-bounds.js.map → get-bounds-center.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/get-bounds-center.ts"],"sourcesContent":["import type { Bounds, Point } from \"./common\"\n\n/**\n * Calculates the center point of a bounds rectangle.\n * @param bounds Bounds object containing minX, minY, maxX, maxY\n * @returns Center point of the bounds\n */\nexport const getBoundsCenter = (bounds: Bounds): Point => ({\n x: (bounds.minX + bounds.maxX) / 2,\n y: (bounds.minY + bounds.maxY) / 2,\n})\n"],"mappings":";AAOO,IAAM,kBAAkB,CAAC,YAA2B;AAAA,EACzD,IAAI,OAAO,OAAO,OAAO,QAAQ;AAAA,EACjC,IAAI,OAAO,OAAO,OAAO,QAAQ;AACnC;","names":[]}
|
|
@@ -109,10 +109,11 @@ var isRectOverlappingPolygon = (rect, polygon) => areBoundsOverlappingPolygon(un
|
|
|
109
109
|
var isRectCompletelyInsidePolygon = (rect, polygon) => areBoundsCompletelyInsidePolygon(universalRectToBounds(rect), polygon);
|
|
110
110
|
|
|
111
111
|
export {
|
|
112
|
+
isPointInsideBounds,
|
|
112
113
|
isPointInsidePolygon,
|
|
113
114
|
areBoundsOverlappingPolygon,
|
|
114
115
|
areBoundsCompletelyInsidePolygon,
|
|
115
116
|
isRectOverlappingPolygon,
|
|
116
117
|
isRectCompletelyInsidePolygon
|
|
117
118
|
};
|
|
118
|
-
//# sourceMappingURL=chunk-
|
|
119
|
+
//# sourceMappingURL=chunk-6K6N6UTQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/polygon.ts"],"sourcesContent":["import type { Bounds, Point, UniversalRect } from \"./common\"\nimport { doSegmentsIntersect } from \"./line-intersections\"\n\nexport type Polygon = readonly Point[]\n\nconst universalRectToBounds = (rect: UniversalRect): Bounds => {\n if (\"minX\" in rect) {\n return rect\n }\n\n const halfWidth = rect.width / 2\n const halfHeight = rect.height / 2\n\n return {\n minX: rect.center.x - halfWidth,\n minY: rect.center.y - halfHeight,\n maxX: rect.center.x + halfWidth,\n maxY: rect.center.y + halfHeight,\n }\n}\n\nconst getBoundsCorners = (bounds: Bounds): Point[] => [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n { x: bounds.minX, y: bounds.maxY },\n]\n\nconst getPolygonEdges = (polygon: Polygon): Array<[Point, Point]> => {\n const edges: Array<[Point, Point]> = []\n for (let i = 0; i < polygon.length; i++) {\n const start = polygon[i]\n const end = polygon[(i + 1) % polygon.length]\n edges.push([start, end])\n }\n return edges\n}\n\nconst isPointOnSegment = (point: Point, start: Point, end: Point): boolean => {\n const cross =\n (point.y - start.y) * (end.x - start.x) -\n (point.x - start.x) * (end.y - start.y)\n if (Math.abs(cross) > 1e-9) {\n return false\n }\n\n const dot =\n (point.x - start.x) * (end.x - start.x) +\n (point.y - start.y) * (end.y - start.y)\n if (dot < 0) {\n return false\n }\n\n const squaredLength = (end.x - start.x) ** 2 + (end.y - start.y) ** 2\n if (dot > squaredLength) {\n return false\n }\n\n return true\n}\n\nexport const isPointInsideBounds = (point: Point, bounds: Bounds): boolean =>\n point.x >= bounds.minX &&\n point.x <= bounds.maxX &&\n point.y >= bounds.minY &&\n point.y <= bounds.maxY\n\nexport const isPointInsidePolygon = (\n point: Point,\n polygon: Polygon,\n): boolean => {\n if (polygon.length < 3) return false\n\n const edges = getPolygonEdges(polygon)\n for (const [start, end] of edges) {\n if (isPointOnSegment(point, start, end)) {\n return true\n }\n }\n\n let inside = false\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x\n const yi = polygon[i].y\n const xj = polygon[j].x\n const yj = polygon[j].y\n\n const intersects =\n yi > point.y !== yj > point.y &&\n point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi\n\n if (intersects) {\n inside = !inside\n }\n }\n\n return inside\n}\n\nconst doesPolygonIntersectBounds = (\n bounds: Bounds,\n polygon: Polygon,\n): boolean => {\n const boundsCorners = getBoundsCorners(bounds)\n const boundsEdges: Array<[Point, Point]> = [\n [boundsCorners[0], boundsCorners[1]],\n [boundsCorners[1], boundsCorners[2]],\n [boundsCorners[2], boundsCorners[3]],\n [boundsCorners[3], boundsCorners[0]],\n ]\n\n const polygonEdges = getPolygonEdges(polygon)\n\n for (const [start, end] of polygonEdges) {\n for (const [rectStart, rectEnd] of boundsEdges) {\n if (doSegmentsIntersect(start, end, rectStart, rectEnd)) {\n return true\n }\n }\n }\n\n return false\n}\n\nexport const areBoundsOverlappingPolygon = (\n bounds: Bounds,\n polygon: Polygon,\n): boolean => {\n if (polygon.length < 3) return false\n\n if (polygon.some((point) => isPointInsideBounds(point, bounds))) {\n return true\n }\n\n const corners = getBoundsCorners(bounds)\n if (corners.some((corner) => isPointInsidePolygon(corner, polygon))) {\n return true\n }\n\n return doesPolygonIntersectBounds(bounds, polygon)\n}\n\nexport const areBoundsCompletelyInsidePolygon = (\n bounds: Bounds,\n polygon: Polygon,\n): boolean => {\n if (polygon.length < 3) return false\n\n const corners = getBoundsCorners(bounds)\n if (!corners.every((corner) => isPointInsidePolygon(corner, polygon))) {\n return false\n }\n\n return !doesPolygonIntersectBounds(bounds, polygon)\n}\n\nexport const isRectOverlappingPolygon = (\n rect: UniversalRect,\n polygon: Polygon,\n): boolean => areBoundsOverlappingPolygon(universalRectToBounds(rect), polygon)\n\nexport const isRectCompletelyInsidePolygon = (\n rect: UniversalRect,\n polygon: Polygon,\n): boolean =>\n areBoundsCompletelyInsidePolygon(universalRectToBounds(rect), polygon)\n"],"mappings":";;;;;AAKA,IAAM,wBAAwB,CAAC,SAAgC;AAC7D,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,KAAK,QAAQ;AAC/B,QAAM,aAAa,KAAK,SAAS;AAEjC,SAAO;AAAA,IACL,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,EACxB;AACF;AAEA,IAAM,mBAAmB,CAAC,WAA4B;AAAA,EACpD,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AAAA,EACjC,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AAAA,EACjC,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AAAA,EACjC,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AACnC;AAEA,IAAM,kBAAkB,CAAC,YAA4C;AACnE,QAAM,QAA+B,CAAC;AACtC,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,QAAQ,QAAQ,CAAC;AACvB,UAAM,MAAM,SAAS,IAAI,KAAK,QAAQ,MAAM;AAC5C,UAAM,KAAK,CAAC,OAAO,GAAG,CAAC;AAAA,EACzB;AACA,SAAO;AACT;AAEA,IAAM,mBAAmB,CAAC,OAAc,OAAc,QAAwB;AAC5E,QA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E,IAAM,gCAAgC,CAC3C,MACA,YAEA,iCAAiC,sBAAsB,IAAI,GAAG,OAAO;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Bounds, Point } from './common.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the center point of a bounds rectangle.
|
|
5
|
+
* @param bounds Bounds object containing minX, minY, maxX, maxY
|
|
6
|
+
* @returns Center point of the bounds
|
|
7
|
+
*/
|
|
8
|
+
declare const getBoundsCenter: (bounds: Bounds) => Point;
|
|
9
|
+
|
|
10
|
+
export { getBoundsCenter };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { doBoundsOverlap } from './bounds-overlap.js';
|
|
|
11
11
|
export { boundsAreaOverlap } from './bounds-area-overlap.js';
|
|
12
12
|
export { boundsDistance } from './bounds-distance.js';
|
|
13
13
|
export { boundsIntersection } from './bounds-intersection.js';
|
|
14
|
-
export { Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon } from './polygon.js';
|
|
14
|
+
export { Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsideBounds, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon } from './polygon.js';
|
|
15
15
|
export { normalizeDegrees } from './normalize-degrees.js';
|
|
16
16
|
export { getBoundsFromPoints } from './get-bounds-from-points.js';
|
|
17
|
-
export {
|
|
17
|
+
export { getBoundsCenter } from './get-bounds-center.js';
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
segmentToSegmentMinDistance
|
|
10
10
|
} from "./chunk-6PD3WN3Y.js";
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
} from "./chunk-
|
|
12
|
+
grid
|
|
13
|
+
} from "./chunk-U45EKA3R.js";
|
|
14
14
|
import {
|
|
15
15
|
normalizeDegrees
|
|
16
16
|
} from "./chunk-P6GW5PWY.js";
|
|
@@ -32,10 +32,11 @@ import "./chunk-MTORG67J.js";
|
|
|
32
32
|
import {
|
|
33
33
|
areBoundsCompletelyInsidePolygon,
|
|
34
34
|
areBoundsOverlappingPolygon,
|
|
35
|
+
isPointInsideBounds,
|
|
35
36
|
isPointInsidePolygon,
|
|
36
37
|
isRectCompletelyInsidePolygon,
|
|
37
38
|
isRectOverlappingPolygon
|
|
38
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-6K6N6UTQ.js";
|
|
39
40
|
import {
|
|
40
41
|
distance,
|
|
41
42
|
doSegmentsIntersect,
|
|
@@ -59,6 +60,9 @@ import {
|
|
|
59
60
|
doBoundsOverlap
|
|
60
61
|
} from "./chunk-CA5ORSO4.js";
|
|
61
62
|
import "./chunk-GYQ2KZV6.js";
|
|
63
|
+
import {
|
|
64
|
+
getBoundsCenter
|
|
65
|
+
} from "./chunk-3WCUPG5S.js";
|
|
62
66
|
import {
|
|
63
67
|
getBoundsFromPoints
|
|
64
68
|
} from "./chunk-5N7UJNVK.js";
|
|
@@ -66,9 +70,6 @@ import {
|
|
|
66
70
|
getUnitVectorFromDirection,
|
|
67
71
|
getUnitVectorFromPointAToB
|
|
68
72
|
} from "./chunk-GIGMPRPV.js";
|
|
69
|
-
import {
|
|
70
|
-
grid
|
|
71
|
-
} from "./chunk-U45EKA3R.js";
|
|
72
73
|
export {
|
|
73
74
|
areBoundsCompletelyInsidePolygon,
|
|
74
75
|
areBoundsOverlappingPolygon,
|
|
@@ -87,12 +88,13 @@ export {
|
|
|
87
88
|
doesSegmentIntersectRect,
|
|
88
89
|
findNearestPointsBetweenBoxSets,
|
|
89
90
|
getBoundingBox,
|
|
91
|
+
getBoundsCenter,
|
|
90
92
|
getBoundsFromPoints,
|
|
91
93
|
getSegmentIntersection,
|
|
92
94
|
getUnitVectorFromDirection,
|
|
93
95
|
getUnitVectorFromPointAToB,
|
|
94
96
|
grid,
|
|
95
|
-
|
|
97
|
+
isPointInsideBounds,
|
|
96
98
|
isPointInsidePolygon,
|
|
97
99
|
isRectCompletelyInsidePolygon,
|
|
98
100
|
isRectOverlappingPolygon,
|
package/dist/polygon.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Point, Bounds, UniversalRect } from './common.js';
|
|
2
2
|
|
|
3
3
|
type Polygon = readonly Point[];
|
|
4
|
+
declare const isPointInsideBounds: (point: Point, bounds: Bounds) => boolean;
|
|
4
5
|
declare const isPointInsidePolygon: (point: Point, polygon: Polygon) => boolean;
|
|
5
6
|
declare const areBoundsOverlappingPolygon: (bounds: Bounds, polygon: Polygon) => boolean;
|
|
6
7
|
declare const areBoundsCompletelyInsidePolygon: (bounds: Bounds, polygon: Polygon) => boolean;
|
|
7
8
|
declare const isRectOverlappingPolygon: (rect: UniversalRect, polygon: Polygon) => boolean;
|
|
8
9
|
declare const isRectCompletelyInsidePolygon: (rect: UniversalRect, polygon: Polygon) => boolean;
|
|
9
10
|
|
|
10
|
-
export { type Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon };
|
|
11
|
+
export { type Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsideBounds, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon };
|
package/dist/polygon.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
areBoundsCompletelyInsidePolygon,
|
|
3
3
|
areBoundsOverlappingPolygon,
|
|
4
|
+
isPointInsideBounds,
|
|
4
5
|
isPointInsidePolygon,
|
|
5
6
|
isRectCompletelyInsidePolygon,
|
|
6
7
|
isRectOverlappingPolygon
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-6K6N6UTQ.js";
|
|
8
9
|
import "./chunk-EFLPMB4J.js";
|
|
9
10
|
export {
|
|
10
11
|
areBoundsCompletelyInsidePolygon,
|
|
11
12
|
areBoundsOverlappingPolygon,
|
|
13
|
+
isPointInsideBounds,
|
|
12
14
|
isPointInsidePolygon,
|
|
13
15
|
isRectCompletelyInsidePolygon,
|
|
14
16
|
isRectOverlappingPolygon
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/polygon.ts"],"sourcesContent":["import type { Bounds, Point, UniversalRect } from \"./common\"\nimport { doSegmentsIntersect } from \"./line-intersections\"\n\nexport type Polygon = readonly Point[]\n\nconst universalRectToBounds = (rect: UniversalRect): Bounds => {\n if (\"minX\" in rect) {\n return rect\n }\n\n const halfWidth = rect.width / 2\n const halfHeight = rect.height / 2\n\n return {\n minX: rect.center.x - halfWidth,\n minY: rect.center.y - halfHeight,\n maxX: rect.center.x + halfWidth,\n maxY: rect.center.y + halfHeight,\n }\n}\n\nconst getBoundsCorners = (bounds: Bounds): Point[] => [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n { x: bounds.minX, y: bounds.maxY },\n]\n\nconst getPolygonEdges = (polygon: Polygon): Array<[Point, Point]> => {\n const edges: Array<[Point, Point]> = []\n for (let i = 0; i < polygon.length; i++) {\n const start = polygon[i]\n const end = polygon[(i + 1) % polygon.length]\n edges.push([start, end])\n }\n return edges\n}\n\nconst isPointOnSegment = (point: Point, start: Point, end: Point): boolean => {\n const cross =\n (point.y - start.y) * (end.x - start.x) -\n (point.x - start.x) * (end.y - start.y)\n if (Math.abs(cross) > 1e-9) {\n return false\n }\n\n const dot =\n (point.x - start.x) * (end.x - start.x) +\n (point.y - start.y) * (end.y - start.y)\n if (dot < 0) {\n return false\n }\n\n const squaredLength = (end.x - start.x) ** 2 + (end.y - start.y) ** 2\n if (dot > squaredLength) {\n return false\n }\n\n return true\n}\n\nconst isPointInsideBounds = (point: Point, bounds: Bounds): boolean =>\n point.x >= bounds.minX &&\n point.x <= bounds.maxX &&\n point.y >= bounds.minY &&\n point.y <= bounds.maxY\n\nexport const isPointInsidePolygon = (\n point: Point,\n polygon: Polygon,\n): boolean => {\n if (polygon.length < 3) return false\n\n const edges = getPolygonEdges(polygon)\n for (const [start, end] of edges) {\n if (isPointOnSegment(point, start, end)) {\n return true\n }\n }\n\n let inside = false\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x\n const yi = polygon[i].y\n const xj = polygon[j].x\n const yj = polygon[j].y\n\n const intersects =\n yi > point.y !== yj > point.y &&\n point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi\n\n if (intersects) {\n inside = !inside\n }\n }\n\n return inside\n}\n\nconst doesPolygonIntersectBounds = (\n bounds: Bounds,\n polygon: Polygon,\n): boolean => {\n const boundsCorners = getBoundsCorners(bounds)\n const boundsEdges: Array<[Point, Point]> = [\n [boundsCorners[0], boundsCorners[1]],\n [boundsCorners[1], boundsCorners[2]],\n [boundsCorners[2], boundsCorners[3]],\n [boundsCorners[3], boundsCorners[0]],\n ]\n\n const polygonEdges = getPolygonEdges(polygon)\n\n for (const [start, end] of polygonEdges) {\n for (const [rectStart, rectEnd] of boundsEdges) {\n if (doSegmentsIntersect(start, end, rectStart, rectEnd)) {\n return true\n }\n }\n }\n\n return false\n}\n\nexport const areBoundsOverlappingPolygon = (\n bounds: Bounds,\n polygon: Polygon,\n): boolean => {\n if (polygon.length < 3) return false\n\n if (polygon.some((point) => isPointInsideBounds(point, bounds))) {\n return true\n }\n\n const corners = getBoundsCorners(bounds)\n if (corners.some((corner) => isPointInsidePolygon(corner, polygon))) {\n return true\n }\n\n return doesPolygonIntersectBounds(bounds, polygon)\n}\n\nexport const areBoundsCompletelyInsidePolygon = (\n bounds: Bounds,\n polygon: Polygon,\n): boolean => {\n if (polygon.length < 3) return false\n\n const corners = getBoundsCorners(bounds)\n if (!corners.every((corner) => isPointInsidePolygon(corner, polygon))) {\n return false\n }\n\n return !doesPolygonIntersectBounds(bounds, polygon)\n}\n\nexport const isRectOverlappingPolygon = (\n rect: UniversalRect,\n polygon: Polygon,\n): boolean => areBoundsOverlappingPolygon(universalRectToBounds(rect), polygon)\n\nexport const isRectCompletelyInsidePolygon = (\n rect: UniversalRect,\n polygon: Polygon,\n): boolean =>\n areBoundsCompletelyInsidePolygon(universalRectToBounds(rect), polygon)\n"],"mappings":";;;;;AAKA,IAAM,wBAAwB,CAAC,SAAgC;AAC7D,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,KAAK,QAAQ;AAC/B,QAAM,aAAa,KAAK,SAAS;AAEjC,SAAO;AAAA,IACL,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,EACxB;AACF;AAEA,IAAM,mBAAmB,CAAC,WAA4B;AAAA,EACpD,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AAAA,EACjC,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AAAA,EACjC,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AAAA,EACjC,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AACnC;AAEA,IAAM,kBAAkB,CAAC,YAA4C;AACnE,QAAM,QAA+B,CAAC;AACtC,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,QAAQ,QAAQ,CAAC;AACvB,UAAM,MAAM,SAAS,IAAI,KAAK,QAAQ,MAAM;AAC5C,UAAM,KAAK,CAAC,OAAO,GAAG,CAAC;AAAA,EACzB;AACA,SAAO;AACT;AAEA,IAAM,mBAAmB,CAAC,OAAc,OAAc,QAAwB;AAC5E,QAAM,SACH,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,MAAM,MACpC,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,MAAM;AACvC,MAAI,KAAK,IAAI,KAAK,IAA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
|
|
|
1
|
-
// src/is-point-in-bounds.ts
|
|
2
|
-
var isPointInBounds = (point, bounds) => {
|
|
3
|
-
return point.x >= bounds.minX && point.x <= bounds.maxX && point.y >= bounds.minY && point.y <= bounds.maxY;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
isPointInBounds
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=chunk-TDJ6LMXM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/is-point-in-bounds.ts"],"sourcesContent":["import type { Bounds, Point } from \"./common\"\n\n/**\n * Determines if a point is inside or on the boundary of a bounds rectangle\n * @param point The point to check\n * @param bounds The bounding rectangle\n * @returns true if the point is within the bounds, false otherwise\n */\nexport const isPointInBounds = (point: Point, bounds: Bounds): boolean => {\n return (\n point.x >= bounds.minX &&\n point.x <= bounds.maxX &&\n point.y >= bounds.minY &&\n point.y <= bounds.maxY\n )\n}\n"],"mappings":";AAQO,IAAM,kBAAkB,CAAC,OAAc,WAA4B;AACxE,SACE,MAAM,KAAK,OAAO,QAClB,MAAM,KAAK,OAAO,QAClB,MAAM,KAAK,OAAO,QAClB,MAAM,KAAK,OAAO;AAEtB;","names":[]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Point, Bounds } from './common.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Determines if a point is inside or on the boundary of a bounds rectangle
|
|
5
|
-
* @param point The point to check
|
|
6
|
-
* @param bounds The bounding rectangle
|
|
7
|
-
* @returns true if the point is within the bounds, false otherwise
|
|
8
|
-
*/
|
|
9
|
-
declare const isPointInBounds: (point: Point, bounds: Bounds) => boolean;
|
|
10
|
-
|
|
11
|
-
export { isPointInBounds };
|
|
File without changes
|