@tscircuit/math-utils 0.0.26 → 0.0.28
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/README.md +3 -3
- package/dist/chunk-P6GW5PWY.js +10 -0
- package/dist/chunk-P6GW5PWY.js.map +1 -0
- package/dist/{chunk-ZBLDFL2R.js → chunk-RCZE5Q5V.js} +16 -9
- package/dist/chunk-RCZE5Q5V.js.map +1 -0
- package/dist/common.d.ts +6 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/normalize-degrees.d.ts +3 -0
- package/dist/normalize-degrees.js +7 -0
- package/dist/normalize-degrees.js.map +1 -0
- package/dist/polygon.d.ts +3 -3
- package/dist/polygon.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-ZBLDFL2R.js.map +0 -1
package/README.md
CHANGED
|
@@ -74,10 +74,10 @@ console.log("Lines intersect:", intersects)
|
|
|
74
74
|
| [`isPointInsidePolygon(point, polygon)`](./src/polygon.ts) | Determine if a point lies inside a polygon. |
|
|
75
75
|
| [`areBoundsOverlappingPolygon(bounds, polygon)`](./src/polygon.ts) | Check whether bounds intersect or are contained by a polygon. |
|
|
76
76
|
| [`areBoundsCompletelyInsidePolygon(bounds, polygon)`](./src/polygon.ts) | Determine if bounds are fully contained within a polygon. |
|
|
77
|
-
| [`isRectOverlappingPolygon(rect, polygon)`](./src/polygon.ts) | Check whether a rectangle defined by
|
|
78
|
-
| [`isRectCompletelyInsidePolygon(rect, polygon)`](./src/polygon.ts) | Determine if a rectangle is fully contained within a polygon. |
|
|
77
|
+
| [`isRectOverlappingPolygon(rect, polygon)`](./src/polygon.ts) | Check whether a rectangle defined by a center point with dimensions or by bounds overlaps a polygon. |
|
|
78
|
+
| [`isRectCompletelyInsidePolygon(rect, polygon)`](./src/polygon.ts) | Determine if a rectangle defined by a center point with dimensions or by bounds is fully contained within a polygon. |
|
|
79
79
|
|
|
80
|
-
`rect` objects
|
|
80
|
+
`rect` objects passed to these helpers can either specify a `center` along with `width` and `height` or provide `Bounds` directly.
|
|
81
81
|
|
|
82
82
|
## Contributing
|
|
83
83
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/normalize-degrees.ts"],"sourcesContent":["export function normalizeDegrees(angle: number): number {\n const normalized = ((angle % 360) + 360) % 360\n return normalized\n}\n"],"mappings":";AAAO,SAAS,iBAAiB,OAAuB;AACtD,QAAM,cAAe,QAAQ,MAAO,OAAO;AAC3C,SAAO;AACT;","names":[]}
|
|
@@ -3,12 +3,19 @@ import {
|
|
|
3
3
|
} from "./chunk-EFLPMB4J.js";
|
|
4
4
|
|
|
5
5
|
// src/polygon.ts
|
|
6
|
-
var
|
|
7
|
-
minX
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
var universalRectToBounds = (rect) => {
|
|
7
|
+
if ("minX" in rect) {
|
|
8
|
+
return rect;
|
|
9
|
+
}
|
|
10
|
+
const halfWidth = rect.width / 2;
|
|
11
|
+
const halfHeight = rect.height / 2;
|
|
12
|
+
return {
|
|
13
|
+
minX: rect.center.x - halfWidth,
|
|
14
|
+
minY: rect.center.y - halfHeight,
|
|
15
|
+
maxX: rect.center.x + halfWidth,
|
|
16
|
+
maxY: rect.center.y + halfHeight
|
|
17
|
+
};
|
|
18
|
+
};
|
|
12
19
|
var getBoundsCorners = (bounds) => [
|
|
13
20
|
{ x: bounds.minX, y: bounds.minY },
|
|
14
21
|
{ x: bounds.maxX, y: bounds.minY },
|
|
@@ -98,8 +105,8 @@ var areBoundsCompletelyInsidePolygon = (bounds, polygon) => {
|
|
|
98
105
|
}
|
|
99
106
|
return !doesPolygonIntersectBounds(bounds, polygon);
|
|
100
107
|
};
|
|
101
|
-
var isRectOverlappingPolygon = (rect, polygon) => areBoundsOverlappingPolygon(
|
|
102
|
-
var isRectCompletelyInsidePolygon = (rect, polygon) => areBoundsCompletelyInsidePolygon(
|
|
108
|
+
var isRectOverlappingPolygon = (rect, polygon) => areBoundsOverlappingPolygon(universalRectToBounds(rect), polygon);
|
|
109
|
+
var isRectCompletelyInsidePolygon = (rect, polygon) => areBoundsCompletelyInsidePolygon(universalRectToBounds(rect), polygon);
|
|
103
110
|
|
|
104
111
|
export {
|
|
105
112
|
isPointInsidePolygon,
|
|
@@ -108,4 +115,4 @@ export {
|
|
|
108
115
|
isRectOverlappingPolygon,
|
|
109
116
|
isRectCompletelyInsidePolygon
|
|
110
117
|
};
|
|
111
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-RCZE5Q5V.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\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,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QAAQ,OAAO;AACpD;AAEO,IAAM,2BAA2B,CACtC,MACA,YACY,4BAA4B,sBAAsB,IAAI,GAAG,OAAO;AAEvE,IAAM,gCAAgC,CAC3C,MACA,YAEA,iCAAiC,sBAAsB,IAAI,GAAG,OAAO;","names":[]}
|
package/dist/common.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { distance, doSegmentsIntersect, doesLineIntersectLine, doesSegmentIntersectRect, getSegmentIntersection, onSegment, orientation, pointToSegmentDistance } from './line-intersections.js';
|
|
2
2
|
export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, computeManhattanDistanceBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox } from './nearest-box.js';
|
|
3
|
-
export { Bounds, Point, Rect } from './common.js';
|
|
3
|
+
export { Bounds, Point, Rect, UniversalRect } from './common.js';
|
|
4
4
|
export { getUnitVectorFromDirection, getUnitVectorFromPointAToB } from './get-unit-vector.js';
|
|
5
5
|
export { GridCellPositions, GridOptions, grid } from './grid.js';
|
|
6
6
|
export { pointToSegmentClosestPoint, segmentToBoundsMinDistance, segmentToBoxMinDistance, segmentToCircleMinDistance, segmentToSegmentMinDistance } from './segment-distance.js';
|
|
@@ -12,3 +12,4 @@ export { boundsAreaOverlap } from './bounds-area-overlap.js';
|
|
|
12
12
|
export { boundsDistance } from './bounds-distance.js';
|
|
13
13
|
export { boundsIntersection } from './bounds-intersection.js';
|
|
14
14
|
export { Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon } from './polygon.js';
|
|
15
|
+
export { normalizeDegrees } from './normalize-degrees.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeDegrees
|
|
3
|
+
} from "./chunk-P6GW5PWY.js";
|
|
1
4
|
import {
|
|
2
5
|
distSq,
|
|
3
6
|
midpoint,
|
|
@@ -11,7 +14,7 @@ import {
|
|
|
11
14
|
isPointInsidePolygon,
|
|
12
15
|
isRectCompletelyInsidePolygon,
|
|
13
16
|
isRectOverlappingPolygon
|
|
14
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-RCZE5Q5V.js";
|
|
15
18
|
import {
|
|
16
19
|
range
|
|
17
20
|
} from "./chunk-KY53E6CT.js";
|
|
@@ -86,6 +89,7 @@ export {
|
|
|
86
89
|
isRectCompletelyInsidePolygon,
|
|
87
90
|
isRectOverlappingPolygon,
|
|
88
91
|
midpoint,
|
|
92
|
+
normalizeDegrees,
|
|
89
93
|
onSegment,
|
|
90
94
|
orientation,
|
|
91
95
|
pointToBoundsDistance,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/polygon.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Point, Bounds,
|
|
1
|
+
import { Point, Bounds, UniversalRect } from './common.js';
|
|
2
2
|
|
|
3
3
|
type Polygon = readonly Point[];
|
|
4
4
|
declare const isPointInsidePolygon: (point: Point, polygon: Polygon) => boolean;
|
|
5
5
|
declare const areBoundsOverlappingPolygon: (bounds: Bounds, polygon: Polygon) => boolean;
|
|
6
6
|
declare const areBoundsCompletelyInsidePolygon: (bounds: Bounds, polygon: Polygon) => boolean;
|
|
7
|
-
declare const isRectOverlappingPolygon: (rect:
|
|
8
|
-
declare const isRectCompletelyInsidePolygon: (rect:
|
|
7
|
+
declare const isRectOverlappingPolygon: (rect: UniversalRect, polygon: Polygon) => boolean;
|
|
8
|
+
declare const isRectCompletelyInsidePolygon: (rect: UniversalRect, polygon: Polygon) => boolean;
|
|
9
9
|
|
|
10
10
|
export { type Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon };
|
package/dist/polygon.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/polygon.ts"],"sourcesContent":["import type { Bounds, Point, Rect } from \"./common\"\nimport { doSegmentsIntersect } from \"./line-intersections\"\n\nexport type Polygon = readonly Point[]\n\nconst rectToBounds = (rect: Rect): Bounds => ({\n minX: rect.x,\n minY: rect.y,\n maxX: rect.x + rect.width,\n maxY: rect.y + rect.height,\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: Rect,\n polygon: Polygon,\n): boolean => areBoundsOverlappingPolygon(rectToBounds(rect), polygon)\n\nexport const isRectCompletelyInsidePolygon = (\n rect: Rect,\n polygon: Polygon,\n): boolean => areBoundsCompletelyInsidePolygon(rectToBounds(rect), polygon)\n"],"mappings":";;;;;AAKA,IAAM,eAAe,CAAC,UAAwB;AAAA,EAC5C,MAAM,KA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