@tscircuit/schematic-trace-solver 0.0.25 → 0.0.26

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.
Files changed (46) hide show
  1. package/.github/workflows/bun-test.yml +8 -0
  2. package/README.md +28 -0
  3. package/bunfig.toml +2 -2
  4. package/dist/index.js +23 -6136
  5. package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +0 -1
  6. package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/SingleNetLabelPlacementSolver_visualize.ts +0 -1
  7. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver.ts +0 -2
  8. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver.ts +0 -1
  9. package/lib/solvers/TraceOverlapShiftSolver/TraceOverlapIssueSolver/TraceOverlapIssueSolver.ts +0 -2
  10. package/lib/solvers/TraceOverlapShiftSolver/TraceOverlapShiftSolver.ts +0 -1
  11. package/package.json +6 -7
  12. package/site/components/DownloadDropdown.tsx +4 -2
  13. package/site/examples/example01-basic.page.tsx +1 -1
  14. package/site/examples/example02.page.tsx +1 -1
  15. package/site/examples/example03.page.tsx +1 -1
  16. package/site/examples/example04-single-symbol.page.tsx +1 -1
  17. package/site/examples/example05.page.tsx +1 -1
  18. package/site/examples/example06.page.tsx +1 -1
  19. package/site/examples/example07.page.tsx +1 -1
  20. package/site/examples/example08.page.tsx +1 -1
  21. package/site/examples/example09.page.tsx +1 -1
  22. package/site/examples/example10.page.tsx +1 -1
  23. package/tests/__snapshots__/svg.snap.svg +3 -0
  24. package/tests/examples/__snapshots__/example01.snap.svg +157 -0
  25. package/tests/examples/__snapshots__/example02.snap.svg +262 -0
  26. package/tests/examples/__snapshots__/example03.snap.svg +282 -0
  27. package/tests/examples/__snapshots__/example04.snap.svg +87 -0
  28. package/tests/examples/__snapshots__/example05.snap.svg +190 -0
  29. package/tests/examples/__snapshots__/example06.snap.svg +94 -0
  30. package/tests/examples/__snapshots__/example07.snap.svg +204 -0
  31. package/tests/examples/__snapshots__/example08.snap.svg +136 -0
  32. package/tests/examples/__snapshots__/example09.snap.svg +484 -0
  33. package/tests/examples/__snapshots__/example10.snap.svg +135 -0
  34. package/tests/examples/example01.test.ts +12 -0
  35. package/tests/examples/example02.test.ts +12 -0
  36. package/tests/examples/example03.test.ts +12 -0
  37. package/tests/examples/example04.test.ts +12 -0
  38. package/tests/examples/example05.test.ts +12 -0
  39. package/tests/examples/example06.test.ts +12 -0
  40. package/tests/examples/example07.test.ts +12 -0
  41. package/tests/examples/example08.test.ts +12 -0
  42. package/tests/examples/example09.test.ts +12 -0
  43. package/tests/examples/example10.test.ts +12 -0
  44. package/tests/fixtures/matcher.ts +62 -0
  45. package/tests/fixtures/preload.ts +1 -0
  46. package/tests/svg.test.ts +11 -0
@@ -0,0 +1,135 @@
1
+ <svg width="640" height="640" viewBox="0 0 640 640" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="100%" height="100%" fill="white" />
3
+ <g>
4
+ <circle data-type="point" data-label="Q1_NPN.1
5
+ y-" data-x="-2.2855604555" data-y="-0.5519250999999993" cx="50.05763517236585" cy="366.03992068458075" r="3" fill="hsl(256, 100%, 50%, 0.8)" />
6
+ </g>
7
+ <g>
8
+ <circle data-type="point" data-label="Q1_NPN.2
9
+ y+" data-x="-2.2855604555000015" data-y="0.5519250999999993" cx="50.057635172365764" cy="273.96007931541925" r="3" fill="hsl(257, 100%, 50%, 0.8)" />
10
+ </g>
11
+ <g>
12
+ <circle data-type="point" data-label="Q1_NPN.3
13
+ x+" data-x="-1.5938689350000006" data-y="0.004526300000001031" cx="107.75644746051344" cy="319.62242975904763" r="3" fill="hsl(258, 100%, 50%, 0.8)" />
14
+ </g>
15
+ <g>
16
+ <circle data-type="point" data-label="Q2_PNP.1
17
+ y-" data-x="3.2144395445" data-y="-0.5519250999999993" cx="508.85098188769814" cy="366.03992068458075" r="3" fill="hsl(79, 100%, 50%, 0.8)" />
18
+ </g>
19
+ <g>
20
+ <circle data-type="point" data-label="Q2_PNP.2
21
+ y+" data-x="3.2144395444999985" data-y="0.5519250999999993" cx="508.850981887698" cy="273.96007931541925" r="3" fill="hsl(80, 100%, 50%, 0.8)" />
22
+ </g>
23
+ <g>
24
+ <circle data-type="point" data-label="Q2_PNP.3
25
+ x+" data-x="3.9061310649999994" data-y="0.004526300000001031" cx="566.5497941758457" cy="319.62242975904763" r="3" fill="hsl(81, 100%, 50%, 0.8)" />
26
+ </g>
27
+ <g>
28
+ <circle data-type="point" data-label="" data-x="-2.2855604555" data-y="-0.5519250999999993" cx="50.05763517236585" cy="366.03992068458075" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
29
+ </g>
30
+ <g>
31
+ <circle data-type="point" data-label="" data-x="3.2144395445" data-y="-0.5519250999999993" cx="508.85098188769814" cy="366.03992068458075" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
32
+ </g>
33
+ <g>
34
+ <circle data-type="point" data-label="" data-x="-2.2855604555000015" data-y="0.5519250999999993" cx="50.057635172365764" cy="273.96007931541925" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
35
+ </g>
36
+ <g>
37
+ <circle data-type="point" data-label="" data-x="3.2144395444999985" data-y="0.5519250999999993" cx="508.850981887698" cy="273.96007931541925" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
38
+ </g>
39
+ <g>
40
+ <circle data-type="point" data-label="" data-x="-1.5938689350000006" data-y="0.004526300000001031" cx="107.75644746051344" cy="319.62242975904763" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
41
+ </g>
42
+ <g>
43
+ <circle data-type="point" data-label="" data-x="3.9061310649999994" data-y="0.004526300000001031" cx="566.5497941758457" cy="319.62242975904763" r="3" fill="hsl(40, 100%, 50%, 0.9)" />
44
+ </g>
45
+ <g>
46
+ <polyline data-points="-2.2855604555,-0.5519250999999993 3.2144395445,-0.5519250999999993" data-type="line" data-label="" points="50.05763517236585,366.03992068458075 508.85098188769814,366.03992068458075" fill="none" stroke="hsl(157, 100%, 50%, 0.8)" stroke-width="1" stroke-dasharray="4 2" />
47
+ </g>
48
+ <g>
49
+ <polyline data-points="-2.2855604555000015,0.5519250999999993 3.2144395444999985,0.5519250999999993" data-type="line" data-label="" points="50.057635172365764,273.96007931541925 508.850981887698,273.96007931541925" fill="none" stroke="hsl(102, 100%, 50%, 0.8)" stroke-width="1" stroke-dasharray="4 2" />
50
+ </g>
51
+ <g>
52
+ <polyline data-points="-1.5938689350000006,0.004526300000001031 3.9061310649999994,0.004526300000001031" data-type="line" data-label="" points="107.75644746051344,319.62242975904763 566.5497941758457,319.62242975904763" fill="none" stroke="hsl(321, 100%, 50%, 0.8)" stroke-width="1" stroke-dasharray="4 2" />
53
+ </g>
54
+ <g>
55
+ <rect data-type="rect" data-label="schematic_component_0" data-x="-2" data-y="0" x="40.00000000000003" y="273.96007931541925" width="67.75644746051341" height="92.0798413691615" fill="hsl(24, 100%, 50%, 0.8)" stroke="black" stroke-width="0.011987968089285714" />
56
+ </g>
57
+ <g>
58
+ <rect data-type="rect" data-label="schematic_component_1" data-x="3.5" data-y="0" x="498.7933467153323" y="273.96007931541925" width="67.75644746051341" height="92.0798413691615" fill="hsl(24, 100%, 50%, 0.8)" stroke="black" stroke-width="0.011987968089285714" />
59
+ </g>
60
+ <g>
61
+ <rect data-type="rect" data-label="" data-x="-2.2855604555" data-y="-0.7529250999999993" x="41.71593795935982" y="366.1233376567108" width="16.683394426012086" height="33.36678885202417" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.011987968089285714" />
62
+ </g>
63
+ <g>
64
+ <rect data-type="rect" data-label="" data-x="3.2144395445" data-y="-0.7529250999999993" x="500.5092846746921" y="366.1233376567108" width="16.68339442601217" height="33.36678885202417" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.011987968089285714" />
65
+ </g>
66
+ <g>
67
+ <rect data-type="rect" data-label="" data-x="-2.2855604555000015" data-y="0.7529250999999993" x="41.71593795935971" y="240.509873491265" width="16.683394426012086" height="33.36678885202417" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.011987968089285714" />
68
+ </g>
69
+ <g>
70
+ <rect data-type="rect" data-label="" data-x="3.2144395444999985" data-y="0.7529250999999993" x="500.50928467469197" y="240.509873491265" width="16.683394426012057" height="33.36678885202417" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.011987968089285714" />
71
+ </g>
72
+ <g>
73
+ <rect data-type="rect" data-label="" data-x="-1.3928689350000008" data-y="0.004526300000001031" x="107.83986443264348" y="311.2807325460416" width="33.36678885202417" height="16.683394426012114" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.011987968089285714" />
74
+ </g>
75
+ <g>
76
+ <rect data-type="rect" data-label="" data-x="4.107131065" data-y="0.004526300000001031" x="566.6332111479758" y="311.2807325460416" width="33.36678885202423" height="16.683394426012114" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.011987968089285714" />
77
+ </g>
78
+ <g id="crosshair" style="display: none">
79
+ <line id="crosshair-h" y1="0" y2="640" stroke="#666" stroke-width="0.5" />
80
+ <line id="crosshair-v" x1="0" x2="640" stroke="#666" stroke-width="0.5" /><text id="coordinates" font-family="monospace" font-size="12" fill="#666"></text>
81
+ </g>
82
+ <script>
83
+ <![CDATA[
84
+ document.currentScript.parentElement.addEventListener('mousemove', (e) => {
85
+ const svg = e.currentTarget;
86
+ const rect = svg.getBoundingClientRect();
87
+ const x = e.clientX - rect.left;
88
+ const y = e.clientY - rect.top;
89
+ const crosshair = svg.getElementById('crosshair');
90
+ const h = svg.getElementById('crosshair-h');
91
+ const v = svg.getElementById('crosshair-v');
92
+ const coords = svg.getElementById('coordinates');
93
+
94
+ crosshair.style.display = 'block';
95
+ h.setAttribute('x1', '0');
96
+ h.setAttribute('x2', '640');
97
+ h.setAttribute('y1', y);
98
+ h.setAttribute('y2', y);
99
+ v.setAttribute('x1', x);
100
+ v.setAttribute('x2', x);
101
+ v.setAttribute('y1', '0');
102
+ v.setAttribute('y2', '640');
103
+
104
+ // Calculate real coordinates using inverse transformation
105
+ const matrix = {
106
+ "a": 83.41697213006042,
107
+ "c": 0,
108
+ "e": 240.71216799037757,
109
+ "b": 0,
110
+ "d": -83.41697213006042,
111
+ "f": 320
112
+ };
113
+ // Manually invert and apply the affine transform
114
+ // Since we only use translate and scale, we can directly compute:
115
+ // x' = (x - tx) / sx
116
+ // y' = (y - ty) / sy
117
+ const sx = matrix.a;
118
+ const sy = matrix.d;
119
+ const tx = matrix.e;
120
+ const ty = matrix.f;
121
+ const realPoint = {
122
+ x: (x - tx) / sx,
123
+ y: (y - ty) / sy // Flip y back since we used negative scale
124
+ }
125
+
126
+ coords.textContent = `(${realPoint.x.toFixed(2)}, ${realPoint.y.toFixed(2)})`;
127
+ coords.setAttribute('x', (x + 5).toString());
128
+ coords.setAttribute('y', (y - 5).toString());
129
+ });
130
+ document.currentScript.parentElement.addEventListener('mouseleave', () => {
131
+ document.currentScript.parentElement.getElementById('crosshair').style.display = 'none';
132
+ });
133
+ ]]>
134
+ </script>
135
+ </svg>
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example01-basic.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example01", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example02.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example02", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example03.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example03", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example04-single-symbol.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example04", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example05.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example05", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example06.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example06", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example07.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example07", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example08.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example08", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example09.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example09", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import { inputProblem } from "site/examples/example10.page"
4
+ import "tests/fixtures/matcher"
5
+
6
+ test("example10", () => {
7
+ const solver = new SchematicTracePipelineSolver(inputProblem)
8
+
9
+ solver.solve()
10
+
11
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
12
+ })
@@ -0,0 +1,62 @@
1
+ import { getSvgFromGraphicsObject, type GraphicsObject } from "graphics-debug"
2
+ import { expect, type MatcherResult } from "bun:test"
3
+ import type { BaseSolver } from "lib/solvers/BaseSolver/BaseSolver"
4
+
5
+ const getAllElms = (graphicsObject: GraphicsObject) => {
6
+ return [
7
+ ...(graphicsObject.lines ?? []),
8
+ ...(graphicsObject.points ?? []),
9
+ ...(graphicsObject.rects ?? []),
10
+ ...(graphicsObject.circles ?? []),
11
+ ...(graphicsObject.texts ?? []),
12
+ ]
13
+ }
14
+
15
+ async function toMatchSolverSnapshot(
16
+ this: any,
17
+ received: BaseSolver,
18
+ testPathOriginal: string,
19
+ svgName?: string,
20
+ ): Promise<MatcherResult> {
21
+ const graphicsObject = received.visualize()
22
+
23
+ const allElms = getAllElms(graphicsObject)
24
+ const lastStep = allElms.reduce((acc, elm) => {
25
+ return Math.max(acc, elm.step ?? 0)
26
+ }, 0)
27
+
28
+ graphicsObject.points = graphicsObject.points?.filter(
29
+ (p) => p.step === lastStep,
30
+ )
31
+ graphicsObject.lines = graphicsObject.lines?.filter(
32
+ (l) => l.step === lastStep,
33
+ )
34
+ graphicsObject.rects = graphicsObject.rects?.filter(
35
+ (r) => r.step === lastStep,
36
+ )
37
+ graphicsObject.circles = graphicsObject.circles?.filter(
38
+ (c) => c.step === lastStep,
39
+ )
40
+ graphicsObject.texts = graphicsObject.texts?.filter(
41
+ (t) => t.step === lastStep,
42
+ )
43
+
44
+ const svg = getSvgFromGraphicsObject(graphicsObject, {
45
+ backgroundColor: "white",
46
+ })
47
+
48
+ return expect(svg).toMatchSvgSnapshot(testPathOriginal, svgName)
49
+ }
50
+
51
+ expect.extend({
52
+ toMatchSolverSnapshot: toMatchSolverSnapshot as any,
53
+ })
54
+
55
+ declare module "bun:test" {
56
+ interface Matchers<T = unknown> {
57
+ toMatchSolverSnapshot(
58
+ testPath: string,
59
+ svgName?: string,
60
+ ): Promise<MatcherResult>
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ import "bun-match-svg"
@@ -0,0 +1,11 @@
1
+ import { expect, test } from "bun:test"
2
+
3
+ const testSvg = `<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
4
+ <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
5
+ </svg>`
6
+
7
+ test("svg snapshot example", async () => {
8
+ // First run will create the snapshot
9
+ // Subsequent runs will compare against the saved snapshot
10
+ await expect(testSvg).toMatchSvgSnapshot(import.meta.path)
11
+ })