@tscircuit/math-utils 0.0.13 → 0.0.14

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,36 @@
1
+ import {
2
+ distance
3
+ } from "./chunk-CHQOCSFB.js";
4
+ import {
5
+ clamp
6
+ } from "./chunk-MHHTZHOJ.js";
7
+
8
+ // src/point-distance.ts
9
+ function pointToBoxDistance(p, box) {
10
+ const halfWidth = box.width / 2;
11
+ const halfHeight = box.height / 2;
12
+ const minX = box.center.x - halfWidth;
13
+ const maxX = box.center.x + halfWidth;
14
+ const minY = box.center.y - halfHeight;
15
+ const maxY = box.center.y + halfHeight;
16
+ if (p.x >= minX && p.x <= maxX && p.y >= minY && p.y <= maxY) {
17
+ return 0;
18
+ }
19
+ const closestX = clamp(p.x, minX, maxX);
20
+ const closestY = clamp(p.y, minY, maxY);
21
+ return distance(p, { x: closestX, y: closestY });
22
+ }
23
+ function pointToBoundsDistance(p, bounds) {
24
+ if (p.x >= bounds.minX && p.x <= bounds.maxX && p.y >= bounds.minY && p.y <= bounds.maxY) {
25
+ return 0;
26
+ }
27
+ const closestX = clamp(p.x, bounds.minX, bounds.maxX);
28
+ const closestY = clamp(p.y, bounds.minY, bounds.maxY);
29
+ return distance(p, { x: closestX, y: closestY });
30
+ }
31
+
32
+ export {
33
+ pointToBoxDistance,
34
+ pointToBoundsDistance
35
+ };
36
+ //# sourceMappingURL=chunk-46MP2ZSF.js.map
@@ -0,0 +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":[]}
package/dist/common.d.ts CHANGED
@@ -2,5 +2,11 @@ type Point = {
2
2
  x: number;
3
3
  y: number;
4
4
  };
5
+ type Bounds = {
6
+ minX: number;
7
+ minY: number;
8
+ maxX: number;
9
+ maxY: number;
10
+ };
5
11
 
6
- export type { Point };
12
+ export type { Bounds, Point };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { distance, doSegmentsIntersect, doesLineIntersectLine, onSegment, orientation, pointToSegmentDistance } from './line-intersections.js';
2
2
  export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox } from './nearest-box.js';
3
- export { Point } from './common.js';
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';
6
6
  export { segmentToBoundsMinDistance, segmentToBoxMinDistance, segmentToCircleMinDistance, segmentToSegmentMinDistance } from './segment-distance.js';
7
+ export { pointToBoundsDistance, pointToBoxDistance } from './point-distance.js';
package/dist/index.js CHANGED
@@ -6,6 +6,10 @@ import {
6
6
  import {
7
7
  grid
8
8
  } from "./chunk-U45EKA3R.js";
9
+ import {
10
+ pointToBoundsDistance,
11
+ pointToBoxDistance
12
+ } from "./chunk-46MP2ZSF.js";
9
13
  import {
10
14
  segmentToBoundsMinDistance,
11
15
  segmentToBoxMinDistance,
@@ -39,6 +43,8 @@ export {
39
43
  grid,
40
44
  onSegment,
41
45
  orientation,
46
+ pointToBoundsDistance,
47
+ pointToBoxDistance,
42
48
  pointToSegmentDistance,
43
49
  segmentToBoundsMinDistance,
44
50
  segmentToBoxMinDistance,
@@ -0,0 +1,15 @@
1
+ import { Point, Bounds } from './common.js';
2
+ import { Box } from './nearest-box.js';
3
+
4
+ /**
5
+ * Returns the minimum distance from a point to a box.
6
+ * If the point is inside the box, the distance is 0.
7
+ */
8
+ declare function pointToBoxDistance(p: Point, box: Box): number;
9
+ /**
10
+ * Returns the minimum distance from a point to a bounds rectangle.
11
+ * If the point is inside the bounds, the distance is 0.
12
+ */
13
+ declare function pointToBoundsDistance(p: Point, bounds: Bounds): number;
14
+
15
+ export { pointToBoundsDistance, pointToBoxDistance };
@@ -0,0 +1,11 @@
1
+ import {
2
+ pointToBoundsDistance,
3
+ pointToBoxDistance
4
+ } from "./chunk-46MP2ZSF.js";
5
+ import "./chunk-CHQOCSFB.js";
6
+ import "./chunk-MHHTZHOJ.js";
7
+ export {
8
+ pointToBoundsDistance,
9
+ pointToBoxDistance
10
+ };
11
+ //# sourceMappingURL=point-distance.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.13",
4
+ "version": "0.0.14",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",