@tscircuit/schematic-trace-solver 0.0.34 → 0.0.36

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 (21) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.js +51 -11
  3. package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +13 -0
  4. package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/SingleNetLabelPlacementSolver.ts +11 -1
  5. package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/geometry.ts +13 -3
  6. package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/solvePortOnlyPin.ts +10 -2
  7. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2.ts +19 -0
  8. package/lib/types/InputProblem.ts +1 -0
  9. package/package.json +2 -2
  10. package/site/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2_01-example17.page.tsx +324 -0
  11. package/tests/examples/__snapshots__/example02.snap.svg +5 -8
  12. package/tests/examples/__snapshots__/example04.snap.svg +15 -12
  13. package/tests/examples/__snapshots__/example15.snap.svg +5 -8
  14. package/tests/examples/__snapshots__/example17.snap.svg +13 -16
  15. package/tests/examples/__snapshots__/example20.snap.svg +235 -0
  16. package/tests/examples/example20.test.tsx +190 -0
  17. package/tests/fixtures/matcher.ts +17 -15
  18. package/tests/fixtures/preload.ts +1 -0
  19. package/tests/solvers/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver_repro01.test.ts +1 -1
  20. package/tests/solvers/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2_01-example17-d1_1-u1_1.test.ts +323 -0
  21. package/tests/solvers/SchematicTraceSingleLineSolver2/__snapshots__/SchematicTraceSingleLineSolver2_01-example17-d1_1-u1_1.snap.svg +160 -0
@@ -0,0 +1,323 @@
1
+ import { SchematicTraceSingleLineSolver2 } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2"
2
+ import { test, expect } from "bun:test"
3
+
4
+ test("SchematicTraceSingleLineSolver2 should solve problem correctly", () => {
5
+ const input = {
6
+ chipMap: {
7
+ schematic_component_0: {
8
+ chipId: "schematic_component_0",
9
+ center: {
10
+ x: 0,
11
+ y: 0,
12
+ },
13
+ width: 2.3,
14
+ height: 1,
15
+ pins: [
16
+ {
17
+ pinId: "U1.1",
18
+ x: -1.15,
19
+ y: 0.30000000000000004,
20
+ },
21
+ {
22
+ pinId: "U1.2",
23
+ x: -1.15,
24
+ y: 0.10000000000000003,
25
+ },
26
+ {
27
+ pinId: "U1.3",
28
+ x: -1.15,
29
+ y: -0.09999999999999998,
30
+ },
31
+ {
32
+ pinId: "U1.4",
33
+ x: -1.15,
34
+ y: -0.30000000000000004,
35
+ },
36
+ {
37
+ pinId: "U1.5",
38
+ x: 1.15,
39
+ y: -0.30000000000000004,
40
+ },
41
+ {
42
+ pinId: "U1.6",
43
+ x: 1.15,
44
+ y: -0.10000000000000003,
45
+ },
46
+ {
47
+ pinId: "U1.7",
48
+ x: 1.15,
49
+ y: 0.09999999999999998,
50
+ },
51
+ {
52
+ pinId: "U1.8",
53
+ x: 1.15,
54
+ y: 0.30000000000000004,
55
+ },
56
+ ],
57
+ },
58
+ schematic_component_1: {
59
+ chipId: "schematic_component_1",
60
+ center: {
61
+ x: -1.1500000000000004,
62
+ y: 1.6700000000000002,
63
+ },
64
+ width: 1.04,
65
+ height: 1.0400000000000005,
66
+ pins: [
67
+ {
68
+ pinId: "D1.1",
69
+ x: -1.1500000000000004,
70
+ y: 1.15,
71
+ },
72
+ {
73
+ pinId: "D1.2",
74
+ x: -1.1500000000000004,
75
+ y: 2.1900000000000004,
76
+ },
77
+ ],
78
+ },
79
+ schematic_component_2: {
80
+ chipId: "schematic_component_2",
81
+ center: {
82
+ x: -2.37,
83
+ y: 0.10000000000000009,
84
+ },
85
+ width: 1.04,
86
+ height: 0.54,
87
+ pins: [
88
+ {
89
+ pinId: "D2.1",
90
+ x: -1.85,
91
+ y: 0.10000000000000002,
92
+ },
93
+ {
94
+ pinId: "D2.2",
95
+ x: -2.89,
96
+ y: 0.10000000000000016,
97
+ },
98
+ ],
99
+ },
100
+ schematic_component_3: {
101
+ chipId: "schematic_component_3",
102
+ center: {
103
+ x: 2.4,
104
+ y: -0.3000000000000007,
105
+ },
106
+ width: 1.1000000000000005,
107
+ height: 0.84,
108
+ pins: [
109
+ {
110
+ pinId: "C1.1",
111
+ x: 1.8499999999999996,
112
+ y: -0.3000000000000007,
113
+ },
114
+ {
115
+ pinId: "C1.2",
116
+ x: 2.95,
117
+ y: -0.3000000000000007,
118
+ },
119
+ ],
120
+ },
121
+ schematic_component_4: {
122
+ chipId: "schematic_component_4",
123
+ center: {
124
+ x: 4.2,
125
+ y: -0.3000000000000007,
126
+ },
127
+ width: 1.0999999999999996,
128
+ height: 0.84,
129
+ pins: [
130
+ {
131
+ pinId: "C2.1",
132
+ x: 3.6500000000000004,
133
+ y: -0.3000000000000007,
134
+ },
135
+ {
136
+ pinId: "C2.2",
137
+ x: 4.75,
138
+ y: -0.3000000000000007,
139
+ },
140
+ ],
141
+ },
142
+ },
143
+ pins: [
144
+ {
145
+ pinId: "U1.1",
146
+ x: -1.15,
147
+ y: 0.30000000000000004,
148
+ chipId: "schematic_component_0",
149
+ },
150
+ {
151
+ pinId: "D1.1",
152
+ x: -1.1500000000000004,
153
+ y: 1.15,
154
+ chipId: "schematic_component_1",
155
+ },
156
+ ],
157
+ inputProblem: {
158
+ chips: [
159
+ {
160
+ chipId: "schematic_component_0",
161
+ center: {
162
+ x: 0,
163
+ y: 0,
164
+ },
165
+ width: 2.3,
166
+ height: 1,
167
+ pins: [
168
+ {
169
+ pinId: "U1.1",
170
+ x: -1.15,
171
+ y: 0.30000000000000004,
172
+ },
173
+ {
174
+ pinId: "U1.2",
175
+ x: -1.15,
176
+ y: 0.10000000000000003,
177
+ },
178
+ {
179
+ pinId: "U1.3",
180
+ x: -1.15,
181
+ y: -0.09999999999999998,
182
+ },
183
+ {
184
+ pinId: "U1.4",
185
+ x: -1.15,
186
+ y: -0.30000000000000004,
187
+ },
188
+ {
189
+ pinId: "U1.5",
190
+ x: 1.15,
191
+ y: -0.30000000000000004,
192
+ },
193
+ {
194
+ pinId: "U1.6",
195
+ x: 1.15,
196
+ y: -0.10000000000000003,
197
+ },
198
+ {
199
+ pinId: "U1.7",
200
+ x: 1.15,
201
+ y: 0.09999999999999998,
202
+ },
203
+ {
204
+ pinId: "U1.8",
205
+ x: 1.15,
206
+ y: 0.30000000000000004,
207
+ },
208
+ ],
209
+ },
210
+ {
211
+ chipId: "schematic_component_1",
212
+ center: {
213
+ x: -1.1500000000000004,
214
+ y: 1.6700000000000002,
215
+ },
216
+ width: 1.04,
217
+ height: 1.0400000000000005,
218
+ pins: [
219
+ {
220
+ pinId: "D1.1",
221
+ x: -1.1500000000000004,
222
+ y: 1.15,
223
+ },
224
+ {
225
+ pinId: "D1.2",
226
+ x: -1.1500000000000004,
227
+ y: 2.1900000000000004,
228
+ },
229
+ ],
230
+ },
231
+ {
232
+ chipId: "schematic_component_2",
233
+ center: {
234
+ x: -2.37,
235
+ y: 0.10000000000000009,
236
+ },
237
+ width: 1.04,
238
+ height: 0.54,
239
+ pins: [
240
+ {
241
+ pinId: "D2.1",
242
+ x: -1.85,
243
+ y: 0.10000000000000002,
244
+ },
245
+ {
246
+ pinId: "D2.2",
247
+ x: -2.89,
248
+ y: 0.10000000000000016,
249
+ },
250
+ ],
251
+ },
252
+ {
253
+ chipId: "schematic_component_3",
254
+ center: {
255
+ x: 2.4,
256
+ y: -0.3000000000000007,
257
+ },
258
+ width: 1.1000000000000005,
259
+ height: 0.84,
260
+ pins: [
261
+ {
262
+ pinId: "C1.1",
263
+ x: 1.8499999999999996,
264
+ y: -0.3000000000000007,
265
+ },
266
+ {
267
+ pinId: "C1.2",
268
+ x: 2.95,
269
+ y: -0.3000000000000007,
270
+ },
271
+ ],
272
+ },
273
+ {
274
+ chipId: "schematic_component_4",
275
+ center: {
276
+ x: 4.2,
277
+ y: -0.3000000000000007,
278
+ },
279
+ width: 1.0999999999999996,
280
+ height: 0.84,
281
+ pins: [
282
+ {
283
+ pinId: "C2.1",
284
+ x: 3.6500000000000004,
285
+ y: -0.3000000000000007,
286
+ },
287
+ {
288
+ pinId: "C2.2",
289
+ x: 4.75,
290
+ y: -0.3000000000000007,
291
+ },
292
+ ],
293
+ },
294
+ ],
295
+ directConnections: [
296
+ {
297
+ pinIds: ["U1.5", "C1.1"],
298
+ netId: ".U1 .VCC to .C1 .pin1",
299
+ },
300
+ {
301
+ pinIds: ["C1.2", "C2.1"],
302
+ netId: ".C1 .pin2 to .C2 .pin1",
303
+ },
304
+ {
305
+ pinIds: ["U1.1", "D1.1"],
306
+ netId: ".U1 .OUT1 to .D1 .pin1",
307
+ },
308
+ {
309
+ pinIds: ["U1.2", "D2.1"],
310
+ netId: ".U1 .OUT2 to .D2 .pin1",
311
+ },
312
+ ],
313
+ netConnections: [],
314
+ availableNetLabelOrientations: {},
315
+ maxMspPairDistance: 2.4,
316
+ },
317
+ }
318
+
319
+ const solver = new SchematicTraceSingleLineSolver2(input as any)
320
+ solver.solve()
321
+
322
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
323
+ })
@@ -0,0 +1,160 @@
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="U1.1
5
+ x-" data-x="-1.15" data-y="0.30000000000000004" cx="167.5392670157068" cy="351.8848167539267" r="3" fill="hsl(319, 100%, 50%, 0.8)" />
6
+ </g>
7
+ <g>
8
+ <circle data-type="point" data-label="U1.2
9
+ x-" data-x="-1.15" data-y="0.10000000000000003" cx="167.5392670157068" cy="366.5445026178011" r="3" fill="hsl(320, 100%, 50%, 0.8)" />
10
+ </g>
11
+ <g>
12
+ <circle data-type="point" data-label="U1.3
13
+ x-" data-x="-1.15" data-y="-0.09999999999999998" cx="167.5392670157068" cy="381.2041884816754" r="3" fill="hsl(321, 100%, 50%, 0.8)" />
14
+ </g>
15
+ <g>
16
+ <circle data-type="point" data-label="U1.4
17
+ x-" data-x="-1.15" data-y="-0.30000000000000004" cx="167.5392670157068" cy="395.86387434554973" r="3" fill="hsl(322, 100%, 50%, 0.8)" />
18
+ </g>
19
+ <g>
20
+ <circle data-type="point" data-label="U1.5
21
+ x+" data-x="1.15" data-y="-0.30000000000000004" cx="336.1256544502618" cy="395.86387434554973" r="3" fill="hsl(323, 100%, 50%, 0.8)" />
22
+ </g>
23
+ <g>
24
+ <circle data-type="point" data-label="U1.6
25
+ x+" data-x="1.15" data-y="-0.10000000000000003" cx="336.1256544502618" cy="381.2041884816754" r="3" fill="hsl(324, 100%, 50%, 0.8)" />
26
+ </g>
27
+ <g>
28
+ <circle data-type="point" data-label="U1.7
29
+ x+" data-x="1.15" data-y="0.09999999999999998" cx="336.1256544502618" cy="366.5445026178011" r="3" fill="hsl(325, 100%, 50%, 0.8)" />
30
+ </g>
31
+ <g>
32
+ <circle data-type="point" data-label="U1.8
33
+ x+" data-x="1.15" data-y="0.30000000000000004" cx="336.1256544502618" cy="351.8848167539267" r="3" fill="hsl(326, 100%, 50%, 0.8)" />
34
+ </g>
35
+ <g>
36
+ <circle data-type="point" data-label="D1.1
37
+ y-" data-x="-1.1500000000000004" data-y="1.15" cx="167.5392670157068" cy="289.58115183246076" r="3" fill="hsl(32, 100%, 50%, 0.8)" />
38
+ </g>
39
+ <g>
40
+ <circle data-type="point" data-label="D1.2
41
+ y+" data-x="-1.1500000000000004" data-y="2.1900000000000004" cx="167.5392670157068" cy="213.35078534031413" r="3" fill="hsl(33, 100%, 50%, 0.8)" />
42
+ </g>
43
+ <g>
44
+ <circle data-type="point" data-label="D2.1
45
+ x+" data-x="-1.85" data-y="0.10000000000000002" cx="116.2303664921466" cy="366.5445026178011" r="3" fill="hsl(273, 100%, 50%, 0.8)" />
46
+ </g>
47
+ <g>
48
+ <circle data-type="point" data-label="D2.2
49
+ x-" data-x="-2.89" data-y="0.10000000000000016" cx="40" cy="366.544502617801" r="3" fill="hsl(274, 100%, 50%, 0.8)" />
50
+ </g>
51
+ <g>
52
+ <circle data-type="point" data-label="C1.1
53
+ x-" data-x="1.8499999999999996" data-y="-0.3000000000000007" cx="387.43455497382195" cy="395.8638743455498" r="3" fill="hsl(121, 100%, 50%, 0.8)" />
54
+ </g>
55
+ <g>
56
+ <circle data-type="point" data-label="C1.2
57
+ x+" data-x="2.95" data-y="-0.3000000000000007" cx="468.0628272251309" cy="395.8638743455498" r="3" fill="hsl(122, 100%, 50%, 0.8)" />
58
+ </g>
59
+ <g>
60
+ <circle data-type="point" data-label="C2.1
61
+ x-" data-x="3.6500000000000004" data-y="-0.3000000000000007" cx="519.3717277486911" cy="395.8638743455498" r="3" fill="hsl(2, 100%, 50%, 0.8)" />
62
+ </g>
63
+ <g>
64
+ <circle data-type="point" data-label="C2.2
65
+ x+" data-x="4.75" data-y="-0.3000000000000007" cx="600" cy="395.8638743455498" r="3" fill="hsl(3, 100%, 50%, 0.8)" />
66
+ </g>
67
+ <g>
68
+ <polyline data-points="1.15,-0.30000000000000004 1.8499999999999996,-0.3000000000000007" data-type="line" data-label="" points="336.1256544502618,395.86387434554973 387.43455497382195,395.8638743455498" fill="none" stroke="hsl(160, 100%, 50%, 0.1)" stroke-width="1" />
69
+ </g>
70
+ <g>
71
+ <polyline data-points="2.95,-0.3000000000000007 3.6500000000000004,-0.3000000000000007" data-type="line" data-label="" points="468.0628272251309,395.8638743455498 519.3717277486911,395.8638743455498" fill="none" stroke="hsl(48, 100%, 50%, 0.1)" stroke-width="1" />
72
+ </g>
73
+ <g>
74
+ <polyline data-points="-1.15,0.30000000000000004 -1.1500000000000004,1.15" data-type="line" data-label="" points="167.5392670157068,351.8848167539267 167.5392670157068,289.58115183246076" fill="none" stroke="hsl(280, 100%, 50%, 0.1)" stroke-width="1" />
75
+ </g>
76
+ <g>
77
+ <polyline data-points="-1.15,0.10000000000000003 -1.85,0.10000000000000002" data-type="line" data-label="" points="167.5392670157068,366.5445026178011 116.2303664921466,366.5445026178011" fill="none" stroke="hsl(48, 100%, 50%, 0.1)" stroke-width="1" />
78
+ </g>
79
+ <g>
80
+ <polyline data-points="-1.15,0.30000000000000004 -1.3499999999999999,0.30000000000000004 -1.3499999999999999,0.7250000000000001 -1.1500000000000004,0.7250000000000001 -1.1500000000000004,1.15" data-type="line" data-label="" points="167.5392670157068,351.8848167539267 152.87958115183247,351.8848167539267 152.87958115183247,320.73298429319374 167.5392670157068,320.73298429319374 167.5392670157068,289.58115183246076" fill="none" stroke="red" stroke-width="1" stroke-dasharray="4 4" />
81
+ </g>
82
+ <g>
83
+ <polyline data-points="-1.15,0.30000000000000004 -1.1500000000000004,1.15" data-type="line" data-label="" points="167.5392670157068,351.8848167539267 167.5392670157068,289.58115183246076" fill="none" stroke="blue" stroke-width="1" stroke-dasharray="5 5" />
84
+ </g>
85
+ <g>
86
+ <polyline data-points="-1.15,0.30000000000000004 -1.3499999999999999,0.30000000000000004 -1.3499999999999999,0.7250000000000001 -1.1500000000000004,0.7250000000000001 -1.1500000000000004,1.15" data-type="line" data-label="" points="167.5392670157068,351.8848167539267 152.87958115183247,351.8848167539267 152.87958115183247,320.73298429319374 167.5392670157068,320.73298429319374 167.5392670157068,289.58115183246076" fill="none" stroke="green" stroke-width="1" />
87
+ </g>
88
+ <g>
89
+ <rect data-type="rect" data-label="schematic_component_0" data-x="0" data-y="0" x="167.5392670157068" y="337.22513089005236" width="168.58638743455498" height="73.29842931937173" fill="hsl(24, 100%, 50%, 0.1)" stroke="black" stroke-width="0.013642857142857144" />
90
+ </g>
91
+ <g>
92
+ <rect data-type="rect" data-label="schematic_component_1" data-x="-1.1500000000000004" data-y="1.6700000000000002" x="129.42408376963348" y="213.35078534031413" width="76.2303664921466" height="76.23036649214663" fill="hsl(24, 100%, 50%, 0.1)" stroke="black" stroke-width="0.013642857142857144" />
93
+ </g>
94
+ <g>
95
+ <rect data-type="rect" data-label="schematic_component_2" data-x="-2.37" data-y="0.10000000000000009" x="40" y="346.75392670157066" width="76.2303664921466" height="39.58115183246076" fill="hsl(24, 100%, 50%, 0.1)" stroke="black" stroke-width="0.013642857142857144" />
96
+ </g>
97
+ <g>
98
+ <rect data-type="rect" data-label="schematic_component_3" data-x="2.4" data-y="-0.3000000000000007" x="387.43455497382195" y="365.07853403141365" width="80.62827225130894" height="61.57068062827227" fill="hsl(24, 100%, 50%, 0.1)" stroke="black" stroke-width="0.013642857142857144" />
99
+ </g>
100
+ <g>
101
+ <rect data-type="rect" data-label="schematic_component_4" data-x="4.2" data-y="-0.3000000000000007" x="519.3717277486911" y="365.07853403141365" width="80.62827225130889" height="61.57068062827227" fill="hsl(24, 100%, 50%, 0.1)" stroke="black" stroke-width="0.013642857142857144" />
102
+ </g>
103
+ <g id="crosshair" style="display: none">
104
+ <line id="crosshair-h" y1="0" y2="640" stroke="#666" stroke-width="0.5" />
105
+ <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>
106
+ </g>
107
+ <script>
108
+ <![CDATA[
109
+ document.currentScript.parentElement.addEventListener('mousemove', (e) => {
110
+ const svg = e.currentTarget;
111
+ const rect = svg.getBoundingClientRect();
112
+ const x = e.clientX - rect.left;
113
+ const y = e.clientY - rect.top;
114
+ const crosshair = svg.getElementById('crosshair');
115
+ const h = svg.getElementById('crosshair-h');
116
+ const v = svg.getElementById('crosshair-v');
117
+ const coords = svg.getElementById('coordinates');
118
+
119
+ crosshair.style.display = 'block';
120
+ h.setAttribute('x1', '0');
121
+ h.setAttribute('x2', '640');
122
+ h.setAttribute('y1', y);
123
+ h.setAttribute('y2', y);
124
+ v.setAttribute('x1', x);
125
+ v.setAttribute('x2', x);
126
+ v.setAttribute('y1', '0');
127
+ v.setAttribute('y2', '640');
128
+
129
+ // Calculate real coordinates using inverse transformation
130
+ const matrix = {
131
+ "a": 73.29842931937172,
132
+ "c": 0,
133
+ "e": 251.8324607329843,
134
+ "b": 0,
135
+ "d": -73.29842931937172,
136
+ "f": 373.8743455497382
137
+ };
138
+ // Manually invert and apply the affine transform
139
+ // Since we only use translate and scale, we can directly compute:
140
+ // x' = (x - tx) / sx
141
+ // y' = (y - ty) / sy
142
+ const sx = matrix.a;
143
+ const sy = matrix.d;
144
+ const tx = matrix.e;
145
+ const ty = matrix.f;
146
+ const realPoint = {
147
+ x: (x - tx) / sx,
148
+ y: (y - ty) / sy // Flip y back since we used negative scale
149
+ }
150
+
151
+ coords.textContent = `(${realPoint.x.toFixed(2)}, ${realPoint.y.toFixed(2)})`;
152
+ coords.setAttribute('x', (x + 5).toString());
153
+ coords.setAttribute('y', (y - 5).toString());
154
+ });
155
+ document.currentScript.parentElement.addEventListener('mouseleave', () => {
156
+ document.currentScript.parentElement.getElementById('crosshair').style.display = 'none';
157
+ });
158
+ ]]>
159
+ </script>
160
+ </svg>