@tscircuit/math-utils 0.0.20 → 0.0.22
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-KJEUHNRF.js → chunk-G6ZGTC5I.js} +2 -2
- package/dist/{chunk-MHHTZHOJ.js → chunk-KWIMOCAS.js} +10 -1
- package/dist/chunk-KWIMOCAS.js.map +1 -0
- package/dist/{chunk-OONG4FBI.js → chunk-QE7MTLD2.js} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -3
- package/dist/nearest-box.d.ts +2 -1
- package/dist/nearest-box.js +3 -1
- package/dist/point-distance.js +2 -2
- package/dist/segment-distance.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-MHHTZHOJ.js.map +0 -1
- /package/dist/{chunk-KJEUHNRF.js.map → chunk-G6ZGTC5I.js.map} +0 -0
- /package/dist/{chunk-OONG4FBI.js.map → chunk-QE7MTLD2.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clamp
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KWIMOCAS.js";
|
|
4
4
|
import {
|
|
5
5
|
distance
|
|
6
6
|
} from "./chunk-EFLPMB4J.js";
|
|
@@ -46,4 +46,4 @@ export {
|
|
|
46
46
|
midpoint,
|
|
47
47
|
distSq
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-G6ZGTC5I.js.map
|
|
@@ -26,6 +26,14 @@ function computeDistanceBetweenBoxes(boxA, boxB) {
|
|
|
26
26
|
const distance = Math.hypot(pointA.x - pointB.x, pointA.y - pointB.y);
|
|
27
27
|
return { distance, pointA, pointB };
|
|
28
28
|
}
|
|
29
|
+
function computeGapBetweenBoxes(boxA, boxB) {
|
|
30
|
+
const a = getBoundingBox(boxA);
|
|
31
|
+
const b = getBoundingBox(boxB);
|
|
32
|
+
const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0);
|
|
33
|
+
const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0);
|
|
34
|
+
const distance = Math.hypot(dx, dy);
|
|
35
|
+
return distance;
|
|
36
|
+
}
|
|
29
37
|
function clamp(value, min, max) {
|
|
30
38
|
return Math.max(min, Math.min(max, value));
|
|
31
39
|
}
|
|
@@ -56,7 +64,8 @@ function findNearestPointsBetweenBoxSets(boxSetA, boxSetB) {
|
|
|
56
64
|
export {
|
|
57
65
|
getBoundingBox,
|
|
58
66
|
computeDistanceBetweenBoxes,
|
|
67
|
+
computeGapBetweenBoxes,
|
|
59
68
|
clamp,
|
|
60
69
|
findNearestPointsBetweenBoxSets
|
|
61
70
|
};
|
|
62
|
-
//# sourceMappingURL=chunk-
|
|
71
|
+
//# sourceMappingURL=chunk-KWIMOCAS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/nearest-box.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport type Box = { center: Point; width: number; height: number }\nexport type BoxSet = Box[]\n\nexport type GridCell = { boxes: Box[] }\n\nexport function getBoundingBox(box: Box) {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n return {\n minX: box.center.x - halfWidth,\n maxX: box.center.x + halfWidth,\n minY: box.center.y - halfHeight,\n maxY: box.center.y + halfHeight,\n }\n}\n\nexport function computeDistanceBetweenBoxes(\n boxA: Box,\n boxB: Box,\n): { distance: number; pointA: Point; pointB: Point } {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const pointA: Point = { x: 0, y: 0 }\n const pointB: Point = { x: 0, y: 0 }\n\n if (dx === 0 && dy === 0) {\n // Boxes overlap\n return { distance: 0, pointA: boxA.center, pointB: boxB.center }\n }\n\n // Compute the closest points on the edges\n pointA.x = clamp(boxA.center.x, b.minX, b.maxX)\n pointA.y = clamp(boxA.center.y, b.minY, b.maxY)\n\n pointB.x = clamp(boxB.center.x, a.minX, a.maxX)\n pointB.y = clamp(boxB.center.y, a.minY, a.maxY)\n\n const distance = Math.hypot(pointA.x - pointB.x, pointA.y - pointB.y)\n return { distance, pointA, pointB }\n}\n\nexport function computeGapBetweenBoxes(boxA: Box, boxB: Box): number {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const distance = Math.hypot(dx, dy)\n return distance\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value))\n}\n\nexport function findNearestPointsBetweenBoxSets(\n boxSetA: BoxSet,\n boxSetB: BoxSet,\n): { pointA: Point; pointB: Point; distance: number } {\n let minDistance = Number.POSITIVE_INFINITY\n let nearestPointA: Point = { x: 0, y: 0 }\n let nearestPointB: Point = { x: 0, y: 0 }\n\n for (const boxA of boxSetA) {\n for (const boxB of boxSetB) {\n const { distance, pointA, pointB } = computeDistanceBetweenBoxes(\n boxA,\n boxB,\n )\n if (distance < minDistance) {\n minDistance = distance\n nearestPointA = pointA\n nearestPointB = pointB\n }\n }\n }\n\n return {\n pointA: nearestPointA,\n pointB: nearestPointB,\n distance: minDistance,\n }\n}\n"],"mappings":";AAOO,SAAS,eAAe,KAAU;AACvC,QAAM,YAAY,IAAI,QAAQ;AAC9B,QAAM,aAAa,IAAI,SAAS;AAChC,SAAO;AAAA,IACL,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,EACvB;AACF;AAEO,SAAS,4BACd,MACA,MACoD;AACpD,QAAM,IAAI,eAAe,IAAI;AAC7B,QAAM,IAAI,eAAe,IAAI;AAE7B,QAA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,MAAI,cAAc,OAAO;AACzB,MAAI,gBAAuB,EAAE,GAAG,GAAG,GAAG,EAAE;AACxC,MAAI,gBAAuB,EAAE,GAAG,GAAG,GAAG,EAAE;AAExC,aAAW,QAAQ,SAAS;AAC1B,eAAW,QAAQ,SAAS;AAC1B,YAAM,EAAE,UAAU,QAAQ,OAAO,IAAI;AAAA,QACnC;AAAA,QACA;AAAA,MACF;AACA,UAAI,WAAW,aAAa;AAC1B,sBAAc;AACd,wBAAgB;AAChB,wBAAgB;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clamp
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KWIMOCAS.js";
|
|
4
4
|
import {
|
|
5
5
|
distance,
|
|
6
6
|
doSegmentsIntersect,
|
|
@@ -109,4 +109,4 @@ export {
|
|
|
109
109
|
segmentToCircleMinDistance,
|
|
110
110
|
pointToSegmentClosestPoint
|
|
111
111
|
};
|
|
112
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-QE7MTLD2.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { distance, doSegmentsIntersect, doesLineIntersectLine, doesSegmentIntersectRect, getSegmentIntersection, onSegment, orientation, pointToSegmentDistance } from './line-intersections.js';
|
|
2
|
-
export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox } from './nearest-box.js';
|
|
2
|
+
export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox } from './nearest-box.js';
|
|
3
3
|
export { Bounds, Point } from './common.js';
|
|
4
4
|
export { getUnitVectorFromDirection, getUnitVectorFromPointAToB } from './get-unit-vector.js';
|
|
5
5
|
export { GridCellPositions, GridOptions, grid } from './grid.js';
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
midpoint,
|
|
4
4
|
pointToBoundsDistance,
|
|
5
5
|
pointToBoxDistance
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-G6ZGTC5I.js";
|
|
7
7
|
import "./chunk-MTORG67J.js";
|
|
8
8
|
import {
|
|
9
9
|
range
|
|
@@ -14,13 +14,14 @@ import {
|
|
|
14
14
|
segmentToBoxMinDistance,
|
|
15
15
|
segmentToCircleMinDistance,
|
|
16
16
|
segmentToSegmentMinDistance
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-QE7MTLD2.js";
|
|
18
18
|
import {
|
|
19
19
|
clamp,
|
|
20
20
|
computeDistanceBetweenBoxes,
|
|
21
|
+
computeGapBetweenBoxes,
|
|
21
22
|
findNearestPointsBetweenBoxSets,
|
|
22
23
|
getBoundingBox
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-KWIMOCAS.js";
|
|
24
25
|
import {
|
|
25
26
|
boundsAreaOverlap
|
|
26
27
|
} from "./chunk-YA3GC5BB.js";
|
|
@@ -53,6 +54,7 @@ export {
|
|
|
53
54
|
boundsDistance,
|
|
54
55
|
clamp,
|
|
55
56
|
computeDistanceBetweenBoxes,
|
|
57
|
+
computeGapBetweenBoxes,
|
|
56
58
|
distSq,
|
|
57
59
|
distance,
|
|
58
60
|
doBoundsOverlap,
|
package/dist/nearest-box.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ declare function computeDistanceBetweenBoxes(boxA: Box, boxB: Box): {
|
|
|
20
20
|
pointA: Point;
|
|
21
21
|
pointB: Point;
|
|
22
22
|
};
|
|
23
|
+
declare function computeGapBetweenBoxes(boxA: Box, boxB: Box): number;
|
|
23
24
|
declare function clamp(value: number, min: number, max: number): number;
|
|
24
25
|
declare function findNearestPointsBetweenBoxSets(boxSetA: BoxSet, boxSetB: BoxSet): {
|
|
25
26
|
pointA: Point;
|
|
@@ -27,4 +28,4 @@ declare function findNearestPointsBetweenBoxSets(boxSetA: BoxSet, boxSetB: BoxSe
|
|
|
27
28
|
distance: number;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
export { type Box, type BoxSet, type GridCell, clamp, computeDistanceBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox };
|
|
31
|
+
export { type Box, type BoxSet, type GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox };
|
package/dist/nearest-box.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clamp,
|
|
3
3
|
computeDistanceBetweenBoxes,
|
|
4
|
+
computeGapBetweenBoxes,
|
|
4
5
|
findNearestPointsBetweenBoxSets,
|
|
5
6
|
getBoundingBox
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KWIMOCAS.js";
|
|
7
8
|
export {
|
|
8
9
|
clamp,
|
|
9
10
|
computeDistanceBetweenBoxes,
|
|
11
|
+
computeGapBetweenBoxes,
|
|
10
12
|
findNearestPointsBetweenBoxSets,
|
|
11
13
|
getBoundingBox
|
|
12
14
|
};
|
package/dist/point-distance.js
CHANGED
package/dist/segment-distance.js
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
segmentToBoxMinDistance,
|
|
5
5
|
segmentToCircleMinDistance,
|
|
6
6
|
segmentToSegmentMinDistance
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-QE7MTLD2.js";
|
|
8
|
+
import "./chunk-KWIMOCAS.js";
|
|
9
9
|
import "./chunk-EFLPMB4J.js";
|
|
10
10
|
export {
|
|
11
11
|
pointToSegmentClosestPoint,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nearest-box.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport type Box = { center: Point; width: number; height: number }\nexport type BoxSet = Box[]\n\nexport type GridCell = { boxes: Box[] }\n\nexport function getBoundingBox(box: Box) {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n return {\n minX: box.center.x - halfWidth,\n maxX: box.center.x + halfWidth,\n minY: box.center.y - halfHeight,\n maxY: box.center.y + halfHeight,\n }\n}\n\nexport function computeDistanceBetweenBoxes(\n boxA: Box,\n boxB: Box,\n): { distance: number; pointA: Point; pointB: Point } {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const pointA: Point = { x: 0, y: 0 }\n const pointB: Point = { x: 0, y: 0 }\n\n if (dx === 0 && dy === 0) {\n // Boxes overlap\n return { distance: 0, pointA: boxA.center, pointB: boxB.center }\n }\n\n // Compute the closest points on the edges\n pointA.x = clamp(boxA.center.x, b.minX, b.maxX)\n pointA.y = clamp(boxA.center.y, b.minY, b.maxY)\n\n pointB.x = clamp(boxB.center.x, a.minX, a.maxX)\n pointB.y = clamp(boxB.center.y, a.minY, a.maxY)\n\n const distance = Math.hypot(pointA.x - pointB.x, pointA.y - pointB.y)\n return { distance, pointA, pointB }\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value))\n}\n\nexport function findNearestPointsBetweenBoxSets(\n boxSetA: BoxSet,\n boxSetB: BoxSet,\n): { pointA: Point; pointB: Point; distance: number } {\n let minDistance = Number.POSITIVE_INFINITY\n let nearestPointA: Point = { x: 0, y: 0 }\n let nearestPointB: Point = { x: 0, y: 0 }\n\n for (const boxA of boxSetA) {\n for (const boxB of boxSetB) {\n const { distance, pointA, pointB } = computeDistanceBetweenBoxes(\n boxA,\n boxB,\n )\n if (distance < minDistance) {\n minDistance = distance\n nearestPointA = pointA\n nearestPointB = pointB\n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