@tscircuit/math-utils 0.0.24 → 0.0.26

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 CHANGED
@@ -71,6 +71,13 @@ console.log("Lines intersect:", intersects)
71
71
  | [`doBoundsOverlap(bounds1, bounds2)`](./src/bounds-overlap.ts) | Determine if two bounding rectangles overlap. |
72
72
  | [`boundsAreaOverlap(bounds1, bounds2)`](./src/bounds-area-overlap.ts) | Area of overlap between two bounding rectangles. |
73
73
  | [`boundsDistance(bounds1, bounds2)`](./src/bounds-distance.ts) | Minimum distance between two bounding rectangles. |
74
+ | [`isPointInsidePolygon(point, polygon)`](./src/polygon.ts) | Determine if a point lies inside a polygon. |
75
+ | [`areBoundsOverlappingPolygon(bounds, polygon)`](./src/polygon.ts) | Check whether bounds intersect or are contained by a polygon. |
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 `x`, `y`, `width`, and `height` overlaps a polygon. |
78
+ | [`isRectCompletelyInsidePolygon(rect, polygon)`](./src/polygon.ts) | Determine if a rectangle is fully contained within a polygon. |
79
+
80
+ `rect` objects are expected to use the `{ x, y, width, height }` convention with `x` and `y` denoting the minimum corner.
74
81
 
75
82
  ## Contributing
76
83
 
@@ -0,0 +1,11 @@
1
+ import { Bounds } from './common.js';
2
+
3
+ /**
4
+ * Calculates the overlapping bounds of two rectangles
5
+ * @param bounds1 First bounding rectangle
6
+ * @param bounds2 Second bounding rectangle
7
+ * @returns The overlapping bounds or null if there is no overlap
8
+ */
9
+ declare const boundsIntersection: (bounds1: Bounds, bounds2: Bounds) => Bounds | null;
10
+
11
+ export { boundsIntersection };
@@ -0,0 +1,7 @@
1
+ import {
2
+ boundsIntersection
3
+ } from "./chunk-S7H7MIDL.js";
4
+ export {
5
+ boundsIntersection
6
+ };
7
+ //# sourceMappingURL=bounds-intersection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,16 @@
1
+ // src/bounds-intersection.ts
2
+ var boundsIntersection = (bounds1, bounds2) => {
3
+ const minX = Math.max(bounds1.minX, bounds2.minX);
4
+ const minY = Math.max(bounds1.minY, bounds2.minY);
5
+ const maxX = Math.min(bounds1.maxX, bounds2.maxX);
6
+ const maxY = Math.min(bounds1.maxY, bounds2.maxY);
7
+ if (minX > maxX || minY > maxY) {
8
+ return null;
9
+ }
10
+ return { minX, minY, maxX, maxY };
11
+ };
12
+
13
+ export {
14
+ boundsIntersection
15
+ };
16
+ //# sourceMappingURL=chunk-S7H7MIDL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bounds-intersection.ts"],"sourcesContent":["import type { Bounds } from \"./common\"\n\n/**\n * Calculates the overlapping bounds of two rectangles\n * @param bounds1 First bounding rectangle\n * @param bounds2 Second bounding rectangle\n * @returns The overlapping bounds or null if there is no overlap\n */\nexport const boundsIntersection = (\n bounds1: Bounds,\n bounds2: Bounds,\n): Bounds | null => {\n const minX = Math.max(bounds1.minX, bounds2.minX)\n const minY = Math.max(bounds1.minY, bounds2.minY)\n const maxX = Math.min(bounds1.maxX, bounds2.maxX)\n const maxY = Math.min(bounds1.maxY, bounds2.maxY)\n\n if (minX > maxX || minY > maxY) {\n return null\n }\n\n return { minX, minY, maxX, maxY }\n}\n"],"mappings":";AAQO,IAAM,qBAAqB,CAChC,SACA,YACkB;AAClB,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAChD,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAChD,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAChD,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAEhD,MAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,MAAM,MAAM,KAAK;AAClC;","names":[]}
@@ -0,0 +1,111 @@
1
+ import {
2
+ doSegmentsIntersect
3
+ } from "./chunk-EFLPMB4J.js";
4
+
5
+ // src/polygon.ts
6
+ var rectToBounds = (rect) => ({
7
+ minX: rect.x,
8
+ minY: rect.y,
9
+ maxX: rect.x + rect.width,
10
+ maxY: rect.y + rect.height
11
+ });
12
+ var getBoundsCorners = (bounds) => [
13
+ { x: bounds.minX, y: bounds.minY },
14
+ { x: bounds.maxX, y: bounds.minY },
15
+ { x: bounds.maxX, y: bounds.maxY },
16
+ { x: bounds.minX, y: bounds.maxY }
17
+ ];
18
+ var getPolygonEdges = (polygon) => {
19
+ const edges = [];
20
+ for (let i = 0; i < polygon.length; i++) {
21
+ const start = polygon[i];
22
+ const end = polygon[(i + 1) % polygon.length];
23
+ edges.push([start, end]);
24
+ }
25
+ return edges;
26
+ };
27
+ var isPointOnSegment = (point, start, end) => {
28
+ const cross = (point.y - start.y) * (end.x - start.x) - (point.x - start.x) * (end.y - start.y);
29
+ if (Math.abs(cross) > 1e-9) {
30
+ return false;
31
+ }
32
+ const dot = (point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y);
33
+ if (dot < 0) {
34
+ return false;
35
+ }
36
+ const squaredLength = (end.x - start.x) ** 2 + (end.y - start.y) ** 2;
37
+ if (dot > squaredLength) {
38
+ return false;
39
+ }
40
+ return true;
41
+ };
42
+ var isPointInsideBounds = (point, bounds) => point.x >= bounds.minX && point.x <= bounds.maxX && point.y >= bounds.minY && point.y <= bounds.maxY;
43
+ var isPointInsidePolygon = (point, polygon) => {
44
+ if (polygon.length < 3) return false;
45
+ const edges = getPolygonEdges(polygon);
46
+ for (const [start, end] of edges) {
47
+ if (isPointOnSegment(point, start, end)) {
48
+ return true;
49
+ }
50
+ }
51
+ let inside = false;
52
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
53
+ const xi = polygon[i].x;
54
+ const yi = polygon[i].y;
55
+ const xj = polygon[j].x;
56
+ const yj = polygon[j].y;
57
+ const intersects = yi > point.y !== yj > point.y && point.x < (xj - xi) * (point.y - yi) / (yj - yi) + xi;
58
+ if (intersects) {
59
+ inside = !inside;
60
+ }
61
+ }
62
+ return inside;
63
+ };
64
+ var doesPolygonIntersectBounds = (bounds, polygon) => {
65
+ const boundsCorners = getBoundsCorners(bounds);
66
+ const boundsEdges = [
67
+ [boundsCorners[0], boundsCorners[1]],
68
+ [boundsCorners[1], boundsCorners[2]],
69
+ [boundsCorners[2], boundsCorners[3]],
70
+ [boundsCorners[3], boundsCorners[0]]
71
+ ];
72
+ const polygonEdges = getPolygonEdges(polygon);
73
+ for (const [start, end] of polygonEdges) {
74
+ for (const [rectStart, rectEnd] of boundsEdges) {
75
+ if (doSegmentsIntersect(start, end, rectStart, rectEnd)) {
76
+ return true;
77
+ }
78
+ }
79
+ }
80
+ return false;
81
+ };
82
+ var areBoundsOverlappingPolygon = (bounds, polygon) => {
83
+ if (polygon.length < 3) return false;
84
+ if (polygon.some((point) => isPointInsideBounds(point, bounds))) {
85
+ return true;
86
+ }
87
+ const corners = getBoundsCorners(bounds);
88
+ if (corners.some((corner) => isPointInsidePolygon(corner, polygon))) {
89
+ return true;
90
+ }
91
+ return doesPolygonIntersectBounds(bounds, polygon);
92
+ };
93
+ var areBoundsCompletelyInsidePolygon = (bounds, polygon) => {
94
+ if (polygon.length < 3) return false;
95
+ const corners = getBoundsCorners(bounds);
96
+ if (!corners.every((corner) => isPointInsidePolygon(corner, polygon))) {
97
+ return false;
98
+ }
99
+ return !doesPolygonIntersectBounds(bounds, polygon);
100
+ };
101
+ var isRectOverlappingPolygon = (rect, polygon) => areBoundsOverlappingPolygon(rectToBounds(rect), polygon);
102
+ var isRectCompletelyInsidePolygon = (rect, polygon) => areBoundsCompletelyInsidePolygon(rectToBounds(rect), polygon);
103
+
104
+ export {
105
+ isPointInsidePolygon,
106
+ areBoundsOverlappingPolygon,
107
+ areBoundsCompletelyInsidePolygon,
108
+ isRectOverlappingPolygon,
109
+ isRectCompletelyInsidePolygon
110
+ };
111
+ //# sourceMappingURL=chunk-ZBLDFL2R.js.map
@@ -0,0 +1 @@
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 => areBound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Aa;AAC9C,UAAI,oBAAoB,OAAO,KAAK,WAAW,OAAO,GAAG;AACvD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,IAAM,8BAA8B,CACzC,QACA,YACY;AACZ,MAAI,QAAQ,SAAS,EAAG,QAAO;AAE/B,MAAI,QAAQ,KAAK,CAAC,UAAU,oBAAoB,OAAO,MAAM,CAAC,GAAG;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,iBAAiB,MAAM;AACvC,MAAI,QAAQ,KAAK,CAAC,WAAW,qBAAqB,QAAQ,OAAO,CAAC,GAAG;AACnE,WAAO;AAAA,EACT;AAEA,SAAO,2BAA2B,QAAQ,OAAO;AACnD;AAEO,IAAM,mCAAmC,CAC9C,QACA,YACY;AACZ,MAAI,QAAQ,SAAS,EAAG,QAAO;AAE/B,QAAM,UAAU,iBAAiB,MAAM;AACvC,MAAI,CAAC,QAAQ,MAAM,CAAC,WAAW,qBAAqB,QAAQ,OAAO,CAAC,GAAG;AACrE,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,2BAA2B,QAAQ,OAAO;AACpD;AAEO,IAAM,2BAA2B,CACtC,MACA,YACY,4BAA4B,aAAa,IAAI,GAAG,OAAO;AAE9D,IAAM,gCAAgC,CAC3C,MACA,YACY,iCAAiC,aAAa,IAAI,GAAG,OAAO;","names":[]}
package/dist/common.d.ts CHANGED
@@ -8,5 +8,11 @@ type Bounds = {
8
8
  maxX: number;
9
9
  maxY: number;
10
10
  };
11
+ type Rect = {
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ };
11
17
 
12
- export type { Bounds, Point };
18
+ export type { Bounds, Point, Rect };
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 } from './common.js';
3
+ export { Bounds, Point, Rect } 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';
@@ -10,3 +10,5 @@ export { range } from './range.js';
10
10
  export { doBoundsOverlap } from './bounds-overlap.js';
11
11
  export { boundsAreaOverlap } from './bounds-area-overlap.js';
12
12
  export { boundsDistance } from './bounds-distance.js';
13
+ export { boundsIntersection } from './bounds-intersection.js';
14
+ export { Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon } from './polygon.js';
package/dist/index.js CHANGED
@@ -5,6 +5,13 @@ import {
5
5
  pointToBoxDistance
6
6
  } from "./chunk-BLY7FZPX.js";
7
7
  import "./chunk-MTORG67J.js";
8
+ import {
9
+ areBoundsCompletelyInsidePolygon,
10
+ areBoundsOverlappingPolygon,
11
+ isPointInsidePolygon,
12
+ isRectCompletelyInsidePolygon,
13
+ isRectOverlappingPolygon
14
+ } from "./chunk-ZBLDFL2R.js";
8
15
  import {
9
16
  range
10
17
  } from "./chunk-KY53E6CT.js";
@@ -23,12 +30,25 @@ import {
23
30
  findNearestPointsBetweenBoxSets,
24
31
  getBoundingBox
25
32
  } from "./chunk-DRDDWFOS.js";
33
+ import {
34
+ distance,
35
+ doSegmentsIntersect,
36
+ doesLineIntersectLine,
37
+ doesSegmentIntersectRect,
38
+ getSegmentIntersection,
39
+ onSegment,
40
+ orientation,
41
+ pointToSegmentDistance
42
+ } from "./chunk-EFLPMB4J.js";
26
43
  import {
27
44
  boundsAreaOverlap
28
45
  } from "./chunk-YA3GC5BB.js";
29
46
  import {
30
47
  boundsDistance
31
48
  } from "./chunk-KVGAXIWH.js";
49
+ import {
50
+ boundsIntersection
51
+ } from "./chunk-S7H7MIDL.js";
32
52
  import {
33
53
  doBoundsOverlap
34
54
  } from "./chunk-CA5ORSO4.js";
@@ -40,19 +60,12 @@ import {
40
60
  import {
41
61
  grid
42
62
  } from "./chunk-U45EKA3R.js";
43
- import {
44
- distance,
45
- doSegmentsIntersect,
46
- doesLineIntersectLine,
47
- doesSegmentIntersectRect,
48
- getSegmentIntersection,
49
- onSegment,
50
- orientation,
51
- pointToSegmentDistance
52
- } from "./chunk-EFLPMB4J.js";
53
63
  export {
64
+ areBoundsCompletelyInsidePolygon,
65
+ areBoundsOverlappingPolygon,
54
66
  boundsAreaOverlap,
55
67
  boundsDistance,
68
+ boundsIntersection,
56
69
  clamp,
57
70
  computeDistanceBetweenBoxes,
58
71
  computeGapBetweenBoxes,
@@ -69,6 +82,9 @@ export {
69
82
  getUnitVectorFromDirection,
70
83
  getUnitVectorFromPointAToB,
71
84
  grid,
85
+ isPointInsidePolygon,
86
+ isRectCompletelyInsidePolygon,
87
+ isRectOverlappingPolygon,
72
88
  midpoint,
73
89
  onSegment,
74
90
  orientation,
@@ -0,0 +1,10 @@
1
+ import { Point, Bounds, Rect } from './common.js';
2
+
3
+ type Polygon = readonly Point[];
4
+ declare const isPointInsidePolygon: (point: Point, polygon: Polygon) => boolean;
5
+ declare const areBoundsOverlappingPolygon: (bounds: Bounds, polygon: Polygon) => boolean;
6
+ declare const areBoundsCompletelyInsidePolygon: (bounds: Bounds, polygon: Polygon) => boolean;
7
+ declare const isRectOverlappingPolygon: (rect: Rect, polygon: Polygon) => boolean;
8
+ declare const isRectCompletelyInsidePolygon: (rect: Rect, polygon: Polygon) => boolean;
9
+
10
+ export { type Polygon, areBoundsCompletelyInsidePolygon, areBoundsOverlappingPolygon, isPointInsidePolygon, isRectCompletelyInsidePolygon, isRectOverlappingPolygon };
@@ -0,0 +1,16 @@
1
+ import {
2
+ areBoundsCompletelyInsidePolygon,
3
+ areBoundsOverlappingPolygon,
4
+ isPointInsidePolygon,
5
+ isRectCompletelyInsidePolygon,
6
+ isRectOverlappingPolygon
7
+ } from "./chunk-ZBLDFL2R.js";
8
+ import "./chunk-EFLPMB4J.js";
9
+ export {
10
+ areBoundsCompletelyInsidePolygon,
11
+ areBoundsOverlappingPolygon,
12
+ isPointInsidePolygon,
13
+ isRectCompletelyInsidePolygon,
14
+ isRectOverlappingPolygon
15
+ };
16
+ //# sourceMappingURL=polygon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/math-utils",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.24",
4
+ "version": "0.0.26",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",