@tscircuit/schematic-viewer 0.0.1
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/.prettierrc +1 -0
- package/.storybook/main.js +15 -0
- package/.storybook/preview.js +9 -0
- package/README.md +26 -0
- package/ava.config.js +7 -0
- package/dist/Schematic.js +8606 -0
- package/dist/Schematic.js.map +1 -0
- package/dist/lib/hooks/index.js +2170 -0
- package/dist/lib/hooks/index.js.map +1 -0
- package/dist/lib/hooks/use-maybe-promise.js +2170 -0
- package/dist/lib/hooks/use-maybe-promise.js.map +1 -0
- package/dist/lib/render-context/index.js +45 -0
- package/dist/lib/render-context/index.js.map +1 -0
- package/dist/lib/types/core.js +18 -0
- package/dist/lib/types/core.js.map +1 -0
- package/dist/lib/types/index.js +18 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/types/route-solver.js +18 -0
- package/dist/lib/types/route-solver.js.map +1 -0
- package/dist/lib/types/source-component.js +18 -0
- package/dist/lib/types/source-component.js.map +1 -0
- package/dist/lib/types/util.js +18 -0
- package/dist/lib/types/util.js.map +1 -0
- package/dist/lib/utils/direction-to-vec.js +96 -0
- package/dist/lib/utils/direction-to-vec.js.map +1 -0
- package/dist/lib/utils/get-svg-path-bounds.js +51 -0
- package/dist/lib/utils/get-svg-path-bounds.js.map +1 -0
- package/dist/lib/utils/point-math.js +57 -0
- package/dist/lib/utils/point-math.js.map +1 -0
- package/dist/pages/_app.js +2714 -0
- package/dist/pages/_app.js.map +1 -0
- package/dist/pages/index.js +8612 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/led-circuit-react.js +2185 -0
- package/dist/pages/led-circuit-react.js.map +1 -0
- package/dist/pages/led-circuit.js +8656 -0
- package/dist/pages/led-circuit.js.map +1 -0
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.js +47 -0
- package/dist/schematic-components/MovableGrid/MovableGrid.stories.js.map +1 -0
- package/dist/schematic-components/MovableGrid/index.js +34 -0
- package/dist/schematic-components/MovableGrid/index.js.map +1 -0
- package/dist/schematic-components/ProjectComponent.js +8584 -0
- package/dist/schematic-components/ProjectComponent.js.map +1 -0
- package/dist/schematic-components/RenderError.js +40 -0
- package/dist/schematic-components/RenderError.js.map +1 -0
- package/dist/schematic-components/SVGPathComponent.js +90 -0
- package/dist/schematic-components/SVGPathComponent.js.map +1 -0
- package/dist/schematic-components/SchematicBug.js +468 -0
- package/dist/schematic-components/SchematicBug.js.map +1 -0
- package/dist/schematic-components/SchematicComponent.js +8451 -0
- package/dist/schematic-components/SchematicComponent.js.map +1 -0
- package/dist/schematic-components/SchematicGroup.js +32 -0
- package/dist/schematic-components/SchematicGroup.js.map +1 -0
- package/dist/schematic-components/SchematicPort.js +8348 -0
- package/dist/schematic-components/SchematicPort.js.map +1 -0
- package/dist/schematic-components/SchematicText.js +71 -0
- package/dist/schematic-components/SchematicText.js.map +1 -0
- package/dist/schematic-components/SchematicTrace.js +137 -0
- package/dist/schematic-components/SchematicTrace.js.map +1 -0
- package/dist/schematic-components/SimpleCapacitor.js +103 -0
- package/dist/schematic-components/SimpleCapacitor.js.map +1 -0
- package/dist/schematic-components/SimpleDiode.js +101 -0
- package/dist/schematic-components/SimpleDiode.js.map +1 -0
- package/dist/schematic-components/SimpleGround.js +102 -0
- package/dist/schematic-components/SimpleGround.js.map +1 -0
- package/dist/schematic-components/SimpleInductor.js +102 -0
- package/dist/schematic-components/SimpleInductor.js.map +1 -0
- package/dist/schematic-components/SimplePowerSource.js +104 -0
- package/dist/schematic-components/SimplePowerSource.js.map +1 -0
- package/dist/schematic-components/SimpleResistor.js +102 -0
- package/dist/schematic-components/SimpleResistor.js.map +1 -0
- package/dist/schematic-components/index.js +8618 -0
- package/dist/schematic-components/index.js.map +1 -0
- package/next-env.d.ts +5 -0
- package/package.json +52 -0
- package/parsel.d.ts +81 -0
- package/src/Schematic.tsx +40 -0
- package/src/lib/hooks/index.ts +1 -0
- package/src/lib/hooks/use-maybe-promise.ts +14 -0
- package/src/lib/render-context/index.ts +15 -0
- package/src/lib/types/core.ts +179 -0
- package/src/lib/types/index.ts +4 -0
- package/src/lib/types/route-solver.ts +10 -0
- package/src/lib/types/source-component.ts +63 -0
- package/src/lib/types/util.ts +52 -0
- package/src/lib/utils/direction-to-vec.ts +50 -0
- package/src/lib/utils/get-svg-path-bounds.ts +22 -0
- package/src/lib/utils/point-math.ts +26 -0
- package/src/pages/_app.tsx +23 -0
- package/src/pages/index.tsx +10 -0
- package/src/pages/led-circuit-react.tsx +51 -0
- package/src/pages/led-circuit.tsx +91 -0
- package/src/schematic-components/MovableGrid/MovableGrid.stories.tsx +23 -0
- package/src/schematic-components/MovableGrid/index.tsx +4 -0
- package/src/schematic-components/ProjectComponent.tsx +62 -0
- package/src/schematic-components/RenderError.tsx +23 -0
- package/src/schematic-components/SVGPathComponent.tsx +64 -0
- package/src/schematic-components/SchematicBug.tsx +52 -0
- package/src/schematic-components/SchematicComponent.tsx +42 -0
- package/src/schematic-components/SchematicGroup.tsx +3 -0
- package/src/schematic-components/SchematicPort.tsx +39 -0
- package/src/schematic-components/SchematicText.tsx +41 -0
- package/src/schematic-components/SchematicTrace.tsx +48 -0
- package/src/schematic-components/SimpleCapacitor.tsx +29 -0
- package/src/schematic-components/SimpleDiode.tsx +38 -0
- package/src/schematic-components/SimpleGround.tsx +28 -0
- package/src/schematic-components/SimpleInductor.tsx +29 -0
- package/src/schematic-components/SimplePowerSource.tsx +30 -0
- package/src/schematic-components/SimpleResistor.tsx +28 -0
- package/src/schematic-components/index.tsx +17 -0
- package/tsconfig.json +31 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/lib/utils/direction-to-vec.ts
|
|
20
|
+
var direction_to_vec_exports = {};
|
|
21
|
+
__export(direction_to_vec_exports, {
|
|
22
|
+
directionToVec: () => directionToVec,
|
|
23
|
+
rotateClockwise: () => rotateClockwise,
|
|
24
|
+
rotateCounterClockwise: () => rotateCounterClockwise,
|
|
25
|
+
rotateDirection: () => rotateDirection,
|
|
26
|
+
vecToDirection: () => vecToDirection
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(direction_to_vec_exports);
|
|
29
|
+
var directionToVec = (direction) => {
|
|
30
|
+
if (direction === "up")
|
|
31
|
+
return { x: 0, y: -1 };
|
|
32
|
+
else if (direction === "down")
|
|
33
|
+
return { x: 0, y: 1 };
|
|
34
|
+
else if (direction === "left")
|
|
35
|
+
return { x: -1, y: 0 };
|
|
36
|
+
else if (direction === "right")
|
|
37
|
+
return { x: 1, y: 0 };
|
|
38
|
+
else
|
|
39
|
+
throw new Error("Invalid direction");
|
|
40
|
+
};
|
|
41
|
+
var vecToDirection = ({ x, y }) => {
|
|
42
|
+
if (x > y)
|
|
43
|
+
y = 0;
|
|
44
|
+
if (y > x)
|
|
45
|
+
x = 0;
|
|
46
|
+
if (x > 0 && y === 0)
|
|
47
|
+
return "right";
|
|
48
|
+
else if (x < 0 && y === 0)
|
|
49
|
+
return "left";
|
|
50
|
+
else if (x === 0 && y > 0)
|
|
51
|
+
return "down";
|
|
52
|
+
else if (x === 0 && y < 0)
|
|
53
|
+
return "up";
|
|
54
|
+
else
|
|
55
|
+
throw new Error(`Invalid vector for direction conversion (${x}, ${y})`);
|
|
56
|
+
};
|
|
57
|
+
var rotateClockwise = (direction) => {
|
|
58
|
+
if (direction === "up")
|
|
59
|
+
return "right";
|
|
60
|
+
else if (direction === "right")
|
|
61
|
+
return "down";
|
|
62
|
+
else if (direction === "down")
|
|
63
|
+
return "left";
|
|
64
|
+
else if (direction === "left")
|
|
65
|
+
return "up";
|
|
66
|
+
};
|
|
67
|
+
var rotateCounterClockwise = (direction) => {
|
|
68
|
+
if (direction === "up")
|
|
69
|
+
return "left";
|
|
70
|
+
else if (direction === "left")
|
|
71
|
+
return "down";
|
|
72
|
+
else if (direction === "down")
|
|
73
|
+
return "right";
|
|
74
|
+
else if (direction === "right")
|
|
75
|
+
return "up";
|
|
76
|
+
};
|
|
77
|
+
var rotateDirection = (direction, num90DegreeClockwiseTurns) => {
|
|
78
|
+
while (num90DegreeClockwiseTurns > 0) {
|
|
79
|
+
direction = rotateClockwise(direction);
|
|
80
|
+
num90DegreeClockwiseTurns--;
|
|
81
|
+
}
|
|
82
|
+
while (num90DegreeClockwiseTurns < 0) {
|
|
83
|
+
direction = rotateCounterClockwise(direction);
|
|
84
|
+
num90DegreeClockwiseTurns++;
|
|
85
|
+
}
|
|
86
|
+
return direction;
|
|
87
|
+
};
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
directionToVec,
|
|
91
|
+
rotateClockwise,
|
|
92
|
+
rotateCounterClockwise,
|
|
93
|
+
rotateDirection,
|
|
94
|
+
vecToDirection
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=direction-to-vec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/direction-to-vec.ts"],"sourcesContent":["export const directionToVec = (direction: \"up\" | \"down\" | \"left\" | \"right\") => {\n if (direction === \"up\") return { x: 0, y: -1 }\n else if (direction === \"down\") return { x: 0, y: 1 }\n else if (direction === \"left\") return { x: -1, y: 0 }\n else if (direction === \"right\") return { x: 1, y: 0 }\n else throw new Error(\"Invalid direction\")\n}\n\nexport const vecToDirection = ({ x, y }: { x: number; y: number }) => {\n if (x > y) y = 0\n if (y > x) x = 0\n if (x > 0 && y === 0) return \"right\"\n else if (x < 0 && y === 0) return \"left\"\n else if (x === 0 && y > 0) return \"down\"\n else if (x === 0 && y < 0) return \"up\"\n else throw new Error(`Invalid vector for direction conversion (${x}, ${y})`)\n}\n\nexport const rotateClockwise = (\n direction: \"up\" | \"down\" | \"left\" | \"right\"\n) => {\n if (direction === \"up\") return \"right\"\n else if (direction === \"right\") return \"down\"\n else if (direction === \"down\") return \"left\"\n else if (direction === \"left\") return \"up\"\n}\n\nexport const rotateCounterClockwise = (\n direction: \"up\" | \"down\" | \"left\" | \"right\"\n) => {\n if (direction === \"up\") return \"left\"\n else if (direction === \"left\") return \"down\"\n else if (direction === \"down\") return \"right\"\n else if (direction === \"right\") return \"up\"\n}\n\nexport const rotateDirection = (\n direction: \"up\" | \"down\" | \"left\" | \"right\",\n num90DegreeClockwiseTurns: number\n) => {\n while (num90DegreeClockwiseTurns > 0) {\n direction = rotateClockwise(direction)\n num90DegreeClockwiseTurns--\n }\n while (num90DegreeClockwiseTurns < 0) {\n direction = rotateCounterClockwise(direction)\n num90DegreeClockwiseTurns++\n }\n return direction\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,iBAAiB,CAAC,cAAgD;AAC7E,MAAI,cAAc;AAAM,WAAO,EAAE,GAAG,GAAG,GAAG,GAAG;AAAA,WACpC,cAAc;AAAQ,WAAO,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,WAC1C,cAAc;AAAQ,WAAO,EAAE,GAAG,IAAI,GAAG,EAAE;AAAA,WAC3C,cAAc;AAAS,WAAO,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA;AAC/C,UAAM,IAAI,MAAM,mBAAmB;AAC1C;AAEO,IAAM,iBAAiB,CAAC,EAAE,GAAG,EAAE,MAAgC;AACpE,MAAI,IAAI;AAAG,QAAI;AACf,MAAI,IAAI;AAAG,QAAI;AACf,MAAI,IAAI,KAAK,MAAM;AAAG,WAAO;AAAA,WACpB,IAAI,KAAK,MAAM;AAAG,WAAO;AAAA,WACzB,MAAM,KAAK,IAAI;AAAG,WAAO;AAAA,WACzB,MAAM,KAAK,IAAI;AAAG,WAAO;AAAA;AAC7B,UAAM,IAAI,MAAM,4CAA4C,MAAM,IAAI;AAC7E;AAEO,IAAM,kBAAkB,CAC7B,cACG;AACH,MAAI,cAAc;AAAM,WAAO;AAAA,WACtB,cAAc;AAAS,WAAO;AAAA,WAC9B,cAAc;AAAQ,WAAO;AAAA,WAC7B,cAAc;AAAQ,WAAO;AACxC;AAEO,IAAM,yBAAyB,CACpC,cACG;AACH,MAAI,cAAc;AAAM,WAAO;AAAA,WACtB,cAAc;AAAQ,WAAO;AAAA,WAC7B,cAAc;AAAQ,WAAO;AAAA,WAC7B,cAAc;AAAS,WAAO;AACzC;AAEO,IAAM,kBAAkB,CAC7B,WACA,8BACG;AACH,SAAO,4BAA4B,GAAG;AACpC,gBAAY,gBAAgB,SAAS;AACrC;AAAA,EACF;AACA,SAAO,4BAA4B,GAAG;AACpC,gBAAY,uBAAuB,SAAS;AAC5C;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/lib/utils/get-svg-path-bounds.ts
|
|
26
|
+
var get_svg_path_bounds_exports = {};
|
|
27
|
+
__export(get_svg_path_bounds_exports, {
|
|
28
|
+
default: () => get_svg_path_bounds_default,
|
|
29
|
+
getSVGPathBounds: () => getSVGPathBounds
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(get_svg_path_bounds_exports);
|
|
32
|
+
var import_svg_path_bounds = __toESM(require("svg-path-bounds"));
|
|
33
|
+
function getSVGPathBounds(ds) {
|
|
34
|
+
if (typeof ds === "string")
|
|
35
|
+
ds = [ds];
|
|
36
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
37
|
+
for (const d of ds) {
|
|
38
|
+
const [left, top, right, bottom] = (0, import_svg_path_bounds.default)(d);
|
|
39
|
+
minX = Math.min(left, minX);
|
|
40
|
+
maxX = Math.max(right, maxX);
|
|
41
|
+
minY = Math.min(top, minY);
|
|
42
|
+
maxY = Math.max(bottom, maxY);
|
|
43
|
+
}
|
|
44
|
+
return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
|
|
45
|
+
}
|
|
46
|
+
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
getSVGPathBounds
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=get-svg-path-bounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/get-svg-path-bounds.ts"],"sourcesContent":["import svgPathBounds from \"svg-path-bounds\"\n\nexport function getSVGPathBounds(ds: string[] | string) {\n if (typeof ds === \"string\") ds = [ds]\n let minX = Infinity,\n maxX = -Infinity,\n minY = Infinity,\n maxY = -Infinity\n\n for (const d of ds) {\n const [left, top, right, bottom] = svgPathBounds(d)\n\n minX = Math.min(left, minX)\n maxX = Math.max(right, maxX)\n minY = Math.min(top, minY)\n maxY = Math.max(bottom, maxY)\n }\n\n return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY }\n}\n\nexport default getSVGPathBounds\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA0B;AAEnB,SAAS,iBAAiB,IAAuB;AACtD,MAAI,OAAO,OAAO;AAAU,SAAK,CAAC,EAAE;AACpC,MAAI,OAAO,UACT,OAAO,WACP,OAAO,UACP,OAAO;AAET,aAAW,KAAK,IAAI;AAClB,UAAM,CAAC,MAAM,KAAK,OAAO,MAAM,QAAI,uBAAAA,SAAc,CAAC;AAElD,WAAO,KAAK,IAAI,MAAM,IAAI;AAC1B,WAAO,KAAK,IAAI,OAAO,IAAI;AAC3B,WAAO,KAAK,IAAI,KAAK,IAAI;AACzB,WAAO,KAAK,IAAI,QAAQ,IAAI;AAAA,EAC9B;AAEA,SAAO,EAAE,MAAM,MAAM,MAAM,MAAM,OAAO,OAAO,MAAM,QAAQ,OAAO,KAAK;AAC3E;AAEA,IAAO,8BAAQ;","names":["svgPathBounds"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/lib/utils/point-math.ts
|
|
20
|
+
var point_math_exports = {};
|
|
21
|
+
__export(point_math_exports, {
|
|
22
|
+
componentSum: () => componentSum,
|
|
23
|
+
mag: () => mag,
|
|
24
|
+
mult: () => mult,
|
|
25
|
+
norm: () => norm,
|
|
26
|
+
sub: () => sub
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(point_math_exports);
|
|
29
|
+
function sub(p1, p2) {
|
|
30
|
+
return { x: p1.x - p2.x, y: p1.y - p2.y };
|
|
31
|
+
}
|
|
32
|
+
function mult(p1, p2) {
|
|
33
|
+
return { x: p1.x * p2.x, y: p1.y * p2.y };
|
|
34
|
+
}
|
|
35
|
+
function mag(p1, p2) {
|
|
36
|
+
const dx = p1.x - p2.x;
|
|
37
|
+
const dy = p1.y - p2.y;
|
|
38
|
+
return Math.sqrt(dx ** 2 + dy ** 2);
|
|
39
|
+
}
|
|
40
|
+
function componentSum(p1) {
|
|
41
|
+
return p1.x + p1.y;
|
|
42
|
+
}
|
|
43
|
+
function norm(p1) {
|
|
44
|
+
return {
|
|
45
|
+
x: Math.sign(p1.x),
|
|
46
|
+
y: Math.sign(p1.y)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
componentSum,
|
|
52
|
+
mag,
|
|
53
|
+
mult,
|
|
54
|
+
norm,
|
|
55
|
+
sub
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=point-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/point-math.ts"],"sourcesContent":["export type Point = { x: number; y: number }\n\nexport function sub(p1: Point, p2: Point) {\n return { x: p1.x - p2.x, y: p1.y - p2.y }\n}\n\nexport function mult(p1: Point, p2: Point) {\n return { x: p1.x * p2.x, y: p1.y * p2.y }\n}\n\nexport function mag(p1: Point, p2: Point) {\n const dx = p1.x - p2.x\n const dy = p1.y - p2.y\n return Math.sqrt(dx ** 2 + dy ** 2)\n}\n\nexport function componentSum(p1: Point) {\n return p1.x + p1.y\n}\n\nexport function norm(p1: Point) {\n return {\n x: Math.sign(p1.x),\n y: Math.sign(p1.y),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,IAAI,IAAW,IAAW;AACxC,SAAO,EAAE,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE;AAC1C;AAEO,SAAS,KAAK,IAAW,IAAW;AACzC,SAAO,EAAE,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE;AAC1C;AAEO,SAAS,IAAI,IAAW,IAAW;AACxC,QAAM,KAAK,GAAG,IAAI,GAAG;AACrB,QAAM,KAAK,GAAG,IAAI,GAAG;AACrB,SAAO,KAAK,KAAK,MAAM,IAAI,MAAM,CAAC;AACpC;AAEO,SAAS,aAAa,IAAW;AACtC,SAAO,GAAG,IAAI,GAAG;AACnB;AAEO,SAAS,KAAK,IAAW;AAC9B,SAAO;AAAA,IACL,GAAG,KAAK,KAAK,GAAG,CAAC;AAAA,IACjB,GAAG,KAAK,KAAK,GAAG,CAAC;AAAA,EACnB;AACF;","names":[]}
|