@tscircuit/schematic-trace-solver 0.0.33 → 0.0.35

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 (27) hide show
  1. package/dist/index.js +36 -4
  2. package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +25 -4
  3. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2.ts +19 -0
  4. package/package.json +2 -2
  5. package/site/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2_01-example17.page.tsx +324 -0
  6. package/site/examples/example15-rp2040-caps.page.tsx +623 -0
  7. package/site/examples/example16-core-repro51.page.tsx +107 -0
  8. package/site/examples/example17-straight-line-trace.page.tsx +165 -0
  9. package/site/examples/example18.page.tsx +181 -0
  10. package/site/examples/example19.page.tsx +169 -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 +797 -71
  14. package/tests/examples/__snapshots__/example16.snap.svg +40 -86
  15. package/tests/examples/__snapshots__/example17.snap.svg +187 -0
  16. package/tests/examples/__snapshots__/example18.snap.svg +235 -0
  17. package/tests/examples/__snapshots__/example19.snap.svg +195 -0
  18. package/tests/examples/example15.test.tsx +524 -82
  19. package/tests/examples/example16.test.tsx +56 -118
  20. package/tests/examples/example17.test.tsx +171 -0
  21. package/tests/examples/example18.test.tsx +187 -0
  22. package/tests/examples/example19.test.tsx +175 -0
  23. package/tests/fixtures/matcher.ts +17 -15
  24. package/tests/fixtures/preload.ts +1 -0
  25. package/tests/solvers/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver_repro01.test.ts +1 -1
  26. package/tests/solvers/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2_01-example17-d1_1-u1_1.test.ts +323 -0
  27. package/tests/solvers/SchematicTraceSingleLineSolver2/__snapshots__/SchematicTraceSingleLineSolver2_01-example17-d1_1-u1_1.snap.svg +160 -0
@@ -0,0 +1,175 @@
1
+ import { expect } from "bun:test"
2
+ import { test } from "bun:test"
3
+ import { SchematicTracePipelineSolver, type InputProblem } from "lib/index"
4
+ import "tests/fixtures/matcher"
5
+
6
+ const inputProblem = {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: 0,
12
+ y: 0,
13
+ },
14
+ width: 0.4,
15
+ height: 0.8,
16
+ pins: [
17
+ {
18
+ pinId: "U1.6",
19
+ x: 0.6000000000000001,
20
+ y: -0.2,
21
+ },
22
+ {
23
+ pinId: "U1.8",
24
+ x: 0.6000000000000001,
25
+ y: 0,
26
+ },
27
+ {
28
+ pinId: "U1.1",
29
+ x: 0.6000000000000001,
30
+ y: 0.2,
31
+ },
32
+ ],
33
+ },
34
+ {
35
+ chipId: "schematic_component_1",
36
+ center: {
37
+ x: 1.4,
38
+ y: 0.55,
39
+ },
40
+ width: 0.5291665999999999,
41
+ height: 1.0583333000000001,
42
+ pins: [
43
+ {
44
+ pinId: "C2.1",
45
+ x: 1.4002733499999995,
46
+ y: -0.0012093000000001908,
47
+ },
48
+ {
49
+ pinId: "C2.2",
50
+ x: 1.3997266500000003,
51
+ y: 1.1012093000000003,
52
+ },
53
+ ],
54
+ },
55
+ {
56
+ chipId: "schematic_component_2",
57
+ center: {
58
+ x: 2.7,
59
+ y: 1.3,
60
+ },
61
+ width: 1.0583332999999997,
62
+ height: 0.388910699999999,
63
+ pins: [
64
+ {
65
+ pinId: "R1.1",
66
+ x: 2.1487093,
67
+ y: 1.3002732499999994,
68
+ },
69
+ {
70
+ pinId: "R1.2",
71
+ x: 3.2512907000000006,
72
+ y: 1.2997267500000007,
73
+ },
74
+ ],
75
+ },
76
+ {
77
+ chipId: "schematic_component_3",
78
+ center: {
79
+ x: 4.4,
80
+ y: 0,
81
+ },
82
+ width: 0.4,
83
+ height: 0.4,
84
+ pins: [
85
+ {
86
+ pinId: "JP5.1",
87
+ x: 3.8000000000000003,
88
+ y: 0,
89
+ },
90
+ ],
91
+ },
92
+ {
93
+ chipId: "schematic_component_4",
94
+ center: {
95
+ x: 4.4,
96
+ y: -0.9,
97
+ },
98
+ width: 0.4,
99
+ height: 0.4,
100
+ pins: [
101
+ {
102
+ pinId: "JP9.1",
103
+ x: 3.8000000000000003,
104
+ y: -0.9,
105
+ },
106
+ ],
107
+ },
108
+ {
109
+ chipId: "schematic_component_5",
110
+ center: {
111
+ x: 2,
112
+ y: -1.1,
113
+ },
114
+ width: 0.8843008999999997,
115
+ height: 0.5299361999999987,
116
+ pins: [
117
+ {
118
+ pinId: "JP8.1",
119
+ x: 2.4458007999999998,
120
+ y: -1.2015872704999997,
121
+ },
122
+ {
123
+ pinId: "JP8.2",
124
+ x: 2.0034928,
125
+ y: -0.8474009705000005,
126
+ },
127
+ {
128
+ pinId: "JP8.3",
129
+ x: 1.5541992,
130
+ y: -1.2014628704999997,
131
+ },
132
+ ],
133
+ },
134
+ ],
135
+ directConnections: [
136
+ {
137
+ pinIds: ["C2.1", "U1.8"],
138
+ netId: "capacitor.C2 > port.pin1 to .U1 > .pin8",
139
+ },
140
+ {
141
+ pinIds: ["C2.2", "R1.1"],
142
+ netId: "capacitor.C2 > port.pin2 to .R1 > .pin1",
143
+ },
144
+ {
145
+ pinIds: ["R1.1", "U1.1"],
146
+ netId: "resistor.R1 > port.pin1 to .U1 > .pin1",
147
+ },
148
+ {
149
+ pinIds: ["JP5.1", "R1.2"],
150
+ netId: "pinheader.JP5 > port.pin1 to .R1 > .pin2",
151
+ },
152
+ {
153
+ pinIds: ["JP9.1", "R1.2"],
154
+ netId: "pinheader.JP9 > port.pin1 to .R1 > .pin2",
155
+ },
156
+ {
157
+ pinIds: ["JP8.2", "U1.6"],
158
+ netId: "solderjumper.JP8 > port.pin2 to .U1 > .pin6",
159
+ },
160
+ ],
161
+ netConnections: [
162
+ {
163
+ netId: "PAD",
164
+ pinIds: ["R1.2", "JP5.1", "JP9.1"],
165
+ },
166
+ ],
167
+ availableNetLabelOrientations: {},
168
+ maxMspPairDistance: 5,
169
+ } as InputProblem
170
+
171
+ test("example19", () => {
172
+ const solver = new SchematicTracePipelineSolver(inputProblem)
173
+ solver.solve()
174
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
175
+ })
@@ -25,21 +25,23 @@ async function toMatchSolverSnapshot(
25
25
  return Math.max(acc, elm.step ?? 0)
26
26
  }, 0)
27
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
- )
28
+ if (lastStep !== 0) {
29
+ graphicsObject.points = graphicsObject.points?.filter(
30
+ (p) => p.step === lastStep,
31
+ )
32
+ graphicsObject.lines = graphicsObject.lines?.filter(
33
+ (l) => l.step === lastStep,
34
+ )
35
+ graphicsObject.rects = graphicsObject.rects?.filter(
36
+ (r) => r.step === lastStep,
37
+ )
38
+ graphicsObject.circles = graphicsObject.circles?.filter(
39
+ (c) => c.step === lastStep,
40
+ )
41
+ graphicsObject.texts = graphicsObject.texts?.filter(
42
+ (t) => t.step === lastStep,
43
+ )
44
+ }
43
45
 
44
46
  const svg = getSvgFromGraphicsObject(graphicsObject, {
45
47
  backgroundColor: "white",
@@ -1 +1,2 @@
1
1
  import "bun-match-svg"
2
+ import "tests/fixtures/matcher"
@@ -2,7 +2,7 @@ import { test, expect } from "bun:test"
2
2
  import input from "./SchematicTraceSingleLineSolver_repro01.json"
3
3
  import { SchematicTraceSingleLineSolver } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver"
4
4
 
5
- test("SchematicTraceSingleLineSolver_repro01", () => {
5
+ test.skip("SchematicTraceSingleLineSolver_repro01", () => {
6
6
  const solver = new SchematicTraceSingleLineSolver(input as any)
7
7
  solver.solve()
8
8
 
@@ -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
+ })