@tscircuit/math-utils 0.0.14 → 0.0.15
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.
|
@@ -28,9 +28,16 @@ function pointToBoundsDistance(p, bounds) {
|
|
|
28
28
|
const closestY = clamp(p.y, bounds.minY, bounds.maxY);
|
|
29
29
|
return distance(p, { x: closestX, y: closestY });
|
|
30
30
|
}
|
|
31
|
+
function midpoint(p1, p2) {
|
|
32
|
+
return {
|
|
33
|
+
x: (p1.x + p2.x) / 2,
|
|
34
|
+
y: (p1.y + p2.y) / 2
|
|
35
|
+
};
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
export {
|
|
33
39
|
pointToBoxDistance,
|
|
34
|
-
pointToBoundsDistance
|
|
40
|
+
pointToBoundsDistance,
|
|
41
|
+
midpoint
|
|
35
42
|
};
|
|
36
|
-
//# sourceMappingURL=chunk-
|
|
43
|
+
//# sourceMappingURL=chunk-W6CW26U5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/point-distance.ts"],"sourcesContent":["import type { Point, Bounds } from \"./common\"\nimport { distance } from \"./line-intersections\"\nimport { clamp } from \"./nearest-box\"\nimport type { Box } from \"./nearest-box\"\n\n/**\n * Returns the minimum distance from a point to a box.\n * If the point is inside the box, the distance is 0.\n */\nexport function pointToBoxDistance(p: Point, box: Box): number {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n const minX = box.center.x - halfWidth\n const maxX = box.center.x + halfWidth\n const minY = box.center.y - halfHeight\n const maxY = box.center.y + halfHeight\n\n // Check if the point is inside the box\n if (p.x >= minX && p.x <= maxX && p.y >= minY && p.y <= maxY) {\n return 0\n }\n\n // Find the closest point on the box boundary\n const closestX = clamp(p.x, minX, maxX)\n const closestY = clamp(p.y, minY, maxY)\n\n // Calculate the distance to the closest point\n return distance(p, { x: closestX, y: closestY })\n}\n\n/**\n * Returns the minimum distance from a point to a bounds rectangle.\n * If the point is inside the bounds, the distance is 0.\n */\nexport function pointToBoundsDistance(p: Point, bounds: Bounds): number {\n // Check if the point is inside the bounds\n if (\n p.x >= bounds.minX &&\n p.x <= bounds.maxX &&\n p.y >= bounds.minY &&\n p.y <= bounds.maxY\n ) {\n return 0\n }\n\n // Find the closest point on the bounds boundary\n const closestX = clamp(p.x, bounds.minX, bounds.maxX)\n const closestY = clamp(p.y, bounds.minY, bounds.maxY)\n\n // Calculate the distance to the closest point\n return distance(p, { x: closestX, y: closestY })\n}\n"],"mappings":";;;;;;;;AASO,SAAS,mBAAmB,GAAU,KAAkB;AAC7D,QAAM,YAAY,IAAI,QAAQ;AAC9B,QAAM,aAAa,IAAI,SAAS;AAChC,QAAM,OAAO,IAAI,OAAO,IAAI;AAC5B,QAAM,OAAO,IAAI,OAAO,IAAI;AAC5B,QAAM,OAAO,IAAI,OAAO,IAAI;AAC5B,QAAM,OAAO,IAAI,OAAO,IAAI;AAG5B,MAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM;AAC5D,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,MAAM,EAAE,GAAG,MAAM,IAAI;AACtC,QAAM,WAAW,MAAM,EAAE,GAAG,MAAM,IAAI;AAGtC,SAAO,SAAS,GAAG,EAAE,GAAG,UAAU,GAAG,SAAS,CAAC;AACjD;AAMO,SAAS,sBAAsB,GAAU,QAAwB;AAEtE,MACE,EAAE,KAAK,OAAO,QACd,EAAE,KAAK,OAAO,QACd,EAAE,KAAK,OAAO,QACd,EAAE,KAAK,OAAO,MACd;AACA,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,MAAM,EAAE,GAAG,OAAO,MAAM,OAAO,IAAI;AACpD,QAAM,WAAW,MAAM,EAAE,GAAG,OAAO,MAAM,OAAO,IAAI;AAGpD,SAAO,SAAS,GAAG,EAAE,GAAG,UAAU,GAAG,SAAS,CAAC;AACjD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/point-distance.ts"],"sourcesContent":["import type { Point, Bounds } from \"./common\"\nimport { distance } from \"./line-intersections\"\nimport { clamp } from \"./nearest-box\"\nimport type { Box } from \"./nearest-box\"\n\n/**\n * Returns the minimum distance from a point to a box.\n * If the point is inside the box, the distance is 0.\n */\nexport function pointToBoxDistance(p: Point, box: Box): number {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n const minX = box.center.x - halfWidth\n const maxX = box.center.x + halfWidth\n const minY = box.center.y - halfHeight\n const maxY = box.center.y + halfHeight\n\n // Check if the point is inside the box\n if (p.x >= minX && p.x <= maxX && p.y >= minY && p.y <= maxY) {\n return 0\n }\n\n // Find the closest point on the box boundary\n const closestX = clamp(p.x, minX, maxX)\n const closestY = clamp(p.y, minY, maxY)\n\n // Calculate the distance to the closest point\n return distance(p, { x: closestX, y: closestY })\n}\n\n/**\n * Returns the minimum distance from a point to a bounds rectangle.\n * If the point is inside the bounds, the distance is 0.\n */\nexport function pointToBoundsDistance(p: Point, bounds: Bounds): number {\n // Check if the point is inside the bounds\n if (\n p.x >= bounds.minX &&\n p.x <= bounds.maxX &&\n p.y >= bounds.minY &&\n p.y <= bounds.maxY\n ) {\n return 0\n }\n\n // Find the closest point on the bounds boundary\n const closestX = clamp(p.x, bounds.minX, bounds.maxX)\n const closestY = clamp(p.y, bounds.minY, bounds.maxY)\n\n // Calculate the distance to the closest point\n return distance(p, { x: closestX, y: closestY })\n}\n\nexport function midpoint(p1: Point, p2: Point): Point {\n return {\n x: (p1.x + p2.x) / 2,\n y: (p1.y + p2.y) / 2,\n }\n}\n"],"mappings":";;;;;;;;AASO,SAAS,mBAAmB,GAAU,KAAkB;AAC7D,QAAM,YAAY,IAAI,QAAQ;AAC9B,QAAM,aAAa,IAAI,SAAS;AAChC,QAAM,OAAO,IAAI,OAAO,IAAI;AAC5B,QAAM,OAAO,IAAI,OAAO,IAAI;AAC5B,QAAM,OAAO,IAAI,OAAO,IAAI;AAC5B,QAAM,OAAO,IAAI,OAAO,IAAI;AAG5B,MAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM;AAC5D,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,MAAM,EAAE,GAAG,MAAM,IAAI;AACtC,QAAM,WAAW,MAAM,EAAE,GAAG,MAAM,IAAI;AAGtC,SAAO,SAAS,GAAG,EAAE,GAAG,UAAU,GAAG,SAAS,CAAC;AACjD;AAMO,SAAS,sBAAsB,GAAU,QAAwB;AAEtE,MACE,EAAE,KAAK,OAAO,QACd,EAAE,KAAK,OAAO,QACd,EAAE,KAAK,OAAO,QACd,EAAE,KAAK,OAAO,MACd;AACA,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,MAAM,EAAE,GAAG,OAAO,MAAM,OAAO,IAAI;AACpD,QAAM,WAAW,MAAM,EAAE,GAAG,OAAO,MAAM,OAAO,IAAI;AAGpD,SAAO,SAAS,GAAG,EAAE,GAAG,UAAU,GAAG,SAAS,CAAC;AACjD;AAEO,SAAS,SAAS,IAAW,IAAkB;AACpD,SAAO;AAAA,IACL,IAAI,GAAG,IAAI,GAAG,KAAK;AAAA,IACnB,IAAI,GAAG,IAAI,GAAG,KAAK;AAAA,EACrB;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ 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';
|
|
6
6
|
export { segmentToBoundsMinDistance, segmentToBoxMinDistance, segmentToCircleMinDistance, segmentToSegmentMinDistance } from './segment-distance.js';
|
|
7
|
-
export { pointToBoundsDistance, pointToBoxDistance } from './point-distance.js';
|
|
7
|
+
export { midpoint, pointToBoundsDistance, pointToBoxDistance } from './point-distance.js';
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
grid
|
|
8
8
|
} from "./chunk-U45EKA3R.js";
|
|
9
9
|
import {
|
|
10
|
+
midpoint,
|
|
10
11
|
pointToBoundsDistance,
|
|
11
12
|
pointToBoxDistance
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-W6CW26U5.js";
|
|
13
14
|
import {
|
|
14
15
|
segmentToBoundsMinDistance,
|
|
15
16
|
segmentToBoxMinDistance,
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
getUnitVectorFromDirection,
|
|
42
43
|
getUnitVectorFromPointAToB,
|
|
43
44
|
grid,
|
|
45
|
+
midpoint,
|
|
44
46
|
onSegment,
|
|
45
47
|
orientation,
|
|
46
48
|
pointToBoundsDistance,
|
package/dist/point-distance.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ declare function pointToBoxDistance(p: Point, box: Box): number;
|
|
|
11
11
|
* If the point is inside the bounds, the distance is 0.
|
|
12
12
|
*/
|
|
13
13
|
declare function pointToBoundsDistance(p: Point, bounds: Bounds): number;
|
|
14
|
+
declare function midpoint(p1: Point, p2: Point): Point;
|
|
14
15
|
|
|
15
|
-
export { pointToBoundsDistance, pointToBoxDistance };
|
|
16
|
+
export { midpoint, pointToBoundsDistance, pointToBoxDistance };
|
package/dist/point-distance.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
midpoint,
|
|
2
3
|
pointToBoundsDistance,
|
|
3
4
|
pointToBoxDistance
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-W6CW26U5.js";
|
|
5
6
|
import "./chunk-CHQOCSFB.js";
|
|
6
7
|
import "./chunk-MHHTZHOJ.js";
|
|
7
8
|
export {
|
|
9
|
+
midpoint,
|
|
8
10
|
pointToBoundsDistance,
|
|
9
11
|
pointToBoxDistance
|
|
10
12
|
};
|