@tscircuit/math-utils 0.0.4 → 0.0.5

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,30 @@
1
+ // src/get-unit-vector.ts
2
+ var getUnitVectorFromPointAToB = (a, b) => {
3
+ const delta = {
4
+ x: b.x - a.x,
5
+ y: b.y - a.y
6
+ };
7
+ const magnitude = Math.sqrt(delta.x ** 2 + delta.y ** 2);
8
+ return {
9
+ x: delta.x / magnitude,
10
+ y: delta.y / magnitude
11
+ };
12
+ };
13
+ var getUnitVectorFromDirection = (direction) => {
14
+ switch (direction) {
15
+ case "up":
16
+ return { x: 0, y: 1 };
17
+ case "down":
18
+ return { x: 0, y: -1 };
19
+ case "left":
20
+ return { x: -1, y: 0 };
21
+ case "right":
22
+ return { x: 1, y: 0 };
23
+ }
24
+ };
25
+
26
+ export {
27
+ getUnitVectorFromPointAToB,
28
+ getUnitVectorFromDirection
29
+ };
30
+ //# sourceMappingURL=chunk-GIGMPRPV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-unit-vector.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport const getUnitVectorFromPointAToB = (a: Point, b: Point): Point => {\n const delta = {\n x: b.x - a.x,\n y: b.y - a.y,\n }\n\n const magnitude = Math.sqrt(delta.x ** 2 + delta.y ** 2)\n\n return {\n x: delta.x / magnitude,\n y: delta.y / magnitude,\n }\n}\n\nexport const getUnitVectorFromDirection = (\n direction: \"up\" | \"down\" | \"left\" | \"right\",\n): Point => {\n switch (direction) {\n case \"up\":\n return { x: 0, y: 1 }\n case \"down\":\n return { x: 0, y: -1 }\n case \"left\":\n return { x: -1, y: 0 }\n case \"right\":\n return { x: 1, y: 0 }\n }\n}\n"],"mappings":";AAEO,IAAM,6BAA6B,CAAC,GAAU,MAAoB;AACvE,QAAM,QAAQ;AAAA,IACZ,GAAG,EAAE,IAAI,EAAE;AAAA,IACX,GAAG,EAAE,IAAI,EAAE;AAAA,EACb;AAEA,QAAM,YAAY,KAAK,KAAK,MAAM,KAAK,IAAI,MAAM,KAAK,CAAC;AAEvD,SAAO;AAAA,IACL,GAAG,MAAM,IAAI;AAAA,IACb,GAAG,MAAM,IAAI;AAAA,EACf;AACF;AAEO,IAAM,6BAA6B,CACxC,cACU;AACV,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,IACtB,KAAK;AACH,aAAO,EAAE,GAAG,GAAG,GAAG,GAAG;AAAA,IACvB,KAAK;AACH,aAAO,EAAE,GAAG,IAAI,GAAG,EAAE;AAAA,IACvB,KAAK;AACH,aAAO,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,EACxB;AACF;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { Point } from './common.js';
2
+
3
+ declare const getUnitVectorFromPointAToB: (a: Point, b: Point) => Point;
4
+ declare const getUnitVectorFromDirection: (direction: "up" | "down" | "left" | "right") => Point;
5
+
6
+ export { getUnitVectorFromDirection, getUnitVectorFromPointAToB };
@@ -0,0 +1,9 @@
1
+ import {
2
+ getUnitVectorFromDirection,
3
+ getUnitVectorFromPointAToB
4
+ } from "./chunk-GIGMPRPV.js";
5
+ export {
6
+ getUnitVectorFromDirection,
7
+ getUnitVectorFromPointAToB
8
+ };
9
+ //# sourceMappingURL=get-unit-vector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
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
3
  export { Point } from './common.js';
4
+ export { getUnitVectorFromDirection, getUnitVectorFromPointAToB } from './get-unit-vector.js';
package/dist/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  import "./chunk-GYQ2KZV6.js";
2
+ import {
3
+ getUnitVectorFromDirection,
4
+ getUnitVectorFromPointAToB
5
+ } from "./chunk-GIGMPRPV.js";
2
6
  import {
3
7
  distance,
4
8
  doSegmentsIntersect,
@@ -21,6 +25,8 @@ export {
21
25
  doesLineIntersectLine,
22
26
  findNearestPointsBetweenBoxSets,
23
27
  getBoundingBox,
28
+ getUnitVectorFromDirection,
29
+ getUnitVectorFromPointAToB,
24
30
  onSegment,
25
31
  orientation,
26
32
  pointToSegmentDistance
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.4",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",