@tscircuit/math-utils 0.0.10 → 0.0.11
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.
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
doSegmentsIntersect,
|
|
3
|
+
pointToSegmentDistance
|
|
4
|
+
} from "./chunk-CHQOCSFB.js";
|
|
5
|
+
|
|
6
|
+
// src/segment-distance.ts
|
|
7
|
+
function segmentToSegmentMinDistance(a, b, u, v) {
|
|
8
|
+
if (a.x === b.x && a.y === b.y) {
|
|
9
|
+
return pointToSegmentDistance(a, u, v);
|
|
10
|
+
}
|
|
11
|
+
if (u.x === v.x && u.y === v.y) {
|
|
12
|
+
return pointToSegmentDistance(u, a, b);
|
|
13
|
+
}
|
|
14
|
+
if (doSegmentsIntersect(a, b, u, v)) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
const distances = [
|
|
18
|
+
pointToSegmentDistance(a, u, v),
|
|
19
|
+
pointToSegmentDistance(b, u, v),
|
|
20
|
+
pointToSegmentDistance(u, a, b),
|
|
21
|
+
pointToSegmentDistance(v, a, b)
|
|
22
|
+
];
|
|
23
|
+
return Math.min(...distances);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
segmentToSegmentMinDistance
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-6C2XJHEO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/segment-distance.ts"],"sourcesContent":["import type { Point } from \"./common\"\nimport {\n distance,\n doSegmentsIntersect,\n pointToSegmentDistance,\n} from \"./line-intersections\"\n\n/**\n * Returns the minimum distance between two line segments.\n */\nexport function segmentToSegmentMinDistance(\n a: Point,\n b: Point,\n u: Point,\n v: Point,\n): number {\n // Handle degenerate cases: segments of zero length\n if (a.x === b.x && a.y === b.y) {\n return pointToSegmentDistance(a, u, v)\n }\n if (u.x === v.x && u.y === v.y) {\n return pointToSegmentDistance(u, a, b)\n }\n\n // Check if segments intersect\n if (doSegmentsIntersect(a, b, u, v)) {\n return 0\n }\n\n // Compute the minimum distance between the segments\n const distances = [\n pointToSegmentDistance(a, u, v),\n pointToSegmentDistance(b, u, v),\n pointToSegmentDistance(u, a, b),\n pointToSegmentDistance(v, a, b),\n ]\n\n return Math.min(...distances)\n}\n"],"mappings":";;;;;;AAUO,SAAS,4BACd,GACA,GACA,GACA,GACQ;AAER,MAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;AAC9B,WAAO,uBAAuB,GAAG,GAAG,CAAC;AAAA,EACvC;AACA,MAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;AAC9B,WAAO,uBAAuB,GAAG,GAAG,CAAC;AAAA,EACvC;AAGA,MAAI,oBAAoB,GAAG,GAAG,GAAG,CAAC,GAAG;AACnC,WAAO;AAAA,EACT;AAGA,QAAM,YAAY;AAAA,IAChB,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,EAChC;AAEA,SAAO,KAAK,IAAI,GAAG,SAAS;AAC9B;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, findNearestP
|
|
|
3
3
|
export { Point } from './common.js';
|
|
4
4
|
export { getUnitVectorFromDirection, getUnitVectorFromPointAToB } from './get-unit-vector.js';
|
|
5
5
|
export { GridCellPositions, GridOptions, grid } from './grid.js';
|
|
6
|
+
export { segmentToSegmentMinDistance } from './segment-distance.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,15 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
grid
|
|
8
8
|
} from "./chunk-U45EKA3R.js";
|
|
9
|
+
import {
|
|
10
|
+
clamp,
|
|
11
|
+
computeDistanceBetweenBoxes,
|
|
12
|
+
findNearestPointsBetweenBoxSets,
|
|
13
|
+
getBoundingBox
|
|
14
|
+
} from "./chunk-MHHTZHOJ.js";
|
|
15
|
+
import {
|
|
16
|
+
segmentToSegmentMinDistance
|
|
17
|
+
} from "./chunk-6C2XJHEO.js";
|
|
9
18
|
import {
|
|
10
19
|
distance,
|
|
11
20
|
doSegmentsIntersect,
|
|
@@ -14,12 +23,6 @@ import {
|
|
|
14
23
|
orientation,
|
|
15
24
|
pointToSegmentDistance
|
|
16
25
|
} from "./chunk-CHQOCSFB.js";
|
|
17
|
-
import {
|
|
18
|
-
clamp,
|
|
19
|
-
computeDistanceBetweenBoxes,
|
|
20
|
-
findNearestPointsBetweenBoxSets,
|
|
21
|
-
getBoundingBox
|
|
22
|
-
} from "./chunk-MHHTZHOJ.js";
|
|
23
26
|
export {
|
|
24
27
|
clamp,
|
|
25
28
|
computeDistanceBetweenBoxes,
|
|
@@ -33,6 +36,7 @@ export {
|
|
|
33
36
|
grid,
|
|
34
37
|
onSegment,
|
|
35
38
|
orientation,
|
|
36
|
-
pointToSegmentDistance
|
|
39
|
+
pointToSegmentDistance,
|
|
40
|
+
segmentToSegmentMinDistance
|
|
37
41
|
};
|
|
38
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|