@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
package/dist/index.js CHANGED
@@ -842,6 +842,20 @@ var SchematicTraceSingleLineSolver2 = class extends BaseSolver {
842
842
  chipAlpha: 0.1,
843
843
  connectionAlpha: 0.1
844
844
  });
845
+ g.lines.push({
846
+ points: this.baseElbow,
847
+ strokeColor: "red",
848
+ strokeDash: "4 4"
849
+ });
850
+ const [pin1, pin2] = this.pins;
851
+ g.lines.push({
852
+ points: [
853
+ { x: pin1.x, y: pin1.y },
854
+ { x: pin2.x, y: pin2.y }
855
+ ],
856
+ strokeColor: "blue",
857
+ strokeDash: "5 5"
858
+ });
845
859
  for (const { path, collisionChipIds: collisionRectIds } of this.queue) {
846
860
  g.lines.push({ points: path, strokeColor: "teal", strokeDash: "2 2" });
847
861
  }
@@ -1927,6 +1941,12 @@ var NetLabelPlacementSolver = class extends BaseSolver {
1927
1941
  const { netConnMap } = getConnectivityMapsFromInputProblem(
1928
1942
  this.inputProblem
1929
1943
  );
1944
+ const pinIdToPinMap = /* @__PURE__ */ new Map();
1945
+ for (const chip of this.inputProblem.chips) {
1946
+ for (const pin of chip.pins) {
1947
+ pinIdToPinMap.set(pin.pinId, pin);
1948
+ }
1949
+ }
1930
1950
  const userNetIdByPinId = {};
1931
1951
  for (const dc of this.inputProblem.directConnections) {
1932
1952
  if (dc.netId) {
@@ -1941,10 +1961,21 @@ var NetLabelPlacementSolver = class extends BaseSolver {
1941
1961
  }
1942
1962
  }
1943
1963
  const groups = [];
1944
- for (const globalConnNetId of Object.keys(netConnMap.netMap)) {
1945
- const pinsInNet = netConnMap.getIdsConnectedToNet(
1964
+ const allPinIds = this.inputProblem.chips.flatMap(
1965
+ (c) => c.pins.map((p) => p.pinId)
1966
+ );
1967
+ const allGlobalConnNetIds = /* @__PURE__ */ new Set();
1968
+ for (const pinId of allPinIds) {
1969
+ const netId = netConnMap.getNetConnectedToId(pinId);
1970
+ if (netId) {
1971
+ allGlobalConnNetIds.add(netId);
1972
+ }
1973
+ }
1974
+ for (const globalConnNetId of allGlobalConnNetIds) {
1975
+ const allIdsInNet = netConnMap.getIdsConnectedToNet(
1946
1976
  globalConnNetId
1947
1977
  );
1978
+ const pinsInNet = allIdsInNet.filter((id) => pinIdToPinMap.has(id));
1948
1979
  const adj = {};
1949
1980
  for (const pid of pinsInNet) adj[pid] = /* @__PURE__ */ new Set();
1950
1981
  for (const t of byGlobal[globalConnNetId] ?? []) {
@@ -2008,12 +2039,13 @@ var NetLabelPlacementSolver = class extends BaseSolver {
2008
2039
  )
2009
2040
  )
2010
2041
  );
2011
- groups.push({
2042
+ const group = {
2012
2043
  globalConnNetId,
2013
2044
  netId: userNetId,
2014
2045
  overlappingTraces: rep,
2015
2046
  mspConnectionPairIds
2016
- });
2047
+ };
2048
+ groups.push(group);
2017
2049
  } else {
2018
2050
  for (const p of component) {
2019
2051
  const userNetId = userNetIdByPinId[p];
@@ -107,6 +107,13 @@ export class NetLabelPlacementSolver extends BaseSolver {
107
107
  this.inputProblem,
108
108
  )
109
109
 
110
+ const pinIdToPinMap = new Map<string, unknown>()
111
+ for (const chip of this.inputProblem.chips) {
112
+ for (const pin of chip.pins) {
113
+ pinIdToPinMap.set(pin.pinId, pin)
114
+ }
115
+ }
116
+
110
117
  // Map pins to user-provided netIds (if any)
111
118
  const userNetIdByPinId: Record<string, string | undefined> = {}
112
119
  for (const dc of this.inputProblem.directConnections) {
@@ -124,11 +131,24 @@ export class NetLabelPlacementSolver extends BaseSolver {
124
131
 
125
132
  const groups: Array<OverlappingSameNetTraceGroup> = []
126
133
 
134
+ const allPinIds = this.inputProblem.chips.flatMap((c) =>
135
+ c.pins.map((p) => p.pinId),
136
+ )
137
+
138
+ const allGlobalConnNetIds = new Set<string>()
139
+ for (const pinId of allPinIds) {
140
+ const netId = netConnMap.getNetConnectedToId(pinId)
141
+ if (netId) {
142
+ allGlobalConnNetIds.add(netId)
143
+ }
144
+ }
145
+
127
146
  // Consider every global connectivity net id
128
- for (const globalConnNetId of Object.keys((netConnMap as any).netMap)) {
129
- const pinsInNet = netConnMap.getIdsConnectedToNet(
147
+ for (const globalConnNetId of allGlobalConnNetIds) {
148
+ const allIdsInNet = netConnMap.getIdsConnectedToNet(
130
149
  globalConnNetId,
131
150
  ) as string[]
151
+ const pinsInNet = allIdsInNet.filter((id) => pinIdToPinMap.has(id))
132
152
 
133
153
  // Build adjacency from solved traces (edges)
134
154
  const adj: Record<string, Set<string>> = {}
@@ -205,12 +225,13 @@ export class NetLabelPlacementSolver extends BaseSolver {
205
225
  ),
206
226
  )
207
227
 
208
- groups.push({
228
+ const group = {
209
229
  globalConnNetId,
210
230
  netId: userNetId,
211
231
  overlappingTraces: rep,
212
232
  mspConnectionPairIds,
213
- })
233
+ }
234
+ groups.push(group)
214
235
  } else {
215
236
  // No traces in this component: place label at each pin that has a user net id
216
237
  for (const p of component) {
@@ -222,6 +222,25 @@ export class SchematicTraceSingleLineSolver2 extends BaseSolver {
222
222
  connectionAlpha: 0.1,
223
223
  })
224
224
 
225
+ // Draw the base elbow
226
+
227
+ g.lines!.push({
228
+ points: this.baseElbow,
229
+ strokeColor: "red",
230
+ strokeDash: "4 4",
231
+ })
232
+
233
+ // Draw the MSP pair connection with a dashed line
234
+ const [pin1, pin2] = this.pins
235
+ g.lines!.push({
236
+ points: [
237
+ { x: pin1.x, y: pin1.y },
238
+ { x: pin2.x, y: pin2.y },
239
+ ],
240
+ strokeColor: "blue",
241
+ strokeDash: "5 5",
242
+ })
243
+
225
244
  // Draw all the new candidates
226
245
  for (const { path, collisionChipIds: collisionRectIds } of this.queue) {
227
246
  g.lines!.push({ points: path, strokeColor: "teal", strokeDash: "2 2" })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/schematic-trace-solver",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.33",
4
+ "version": "0.0.35",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
@@ -15,7 +15,7 @@
15
15
  "@tscircuit/math-utils": "^0.0.19",
16
16
  "@types/bun": "^1.2.21",
17
17
  "bun-match-svg": "^0.0.13",
18
- "calculate-elbow": "^0.0.11",
18
+ "calculate-elbow": "^0.0.12",
19
19
  "connectivity-map": "^1.0.0",
20
20
  "flatbush": "^4.5.0",
21
21
  "graphics-debug": "^0.0.62",
@@ -0,0 +1,324 @@
1
+ import { useMemo } from "react"
2
+ import { GenericSolverDebugger } from "../components/GenericSolverDebugger"
3
+ import { SchematicTraceSingleLineSolver2 } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2"
4
+
5
+ export const inputProblem = {
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
+ export default () => {
320
+ const solver = useMemo(() => {
321
+ return new SchematicTraceSingleLineSolver2(inputProblem as any)
322
+ }, [])
323
+ return <GenericSolverDebugger solver={solver} />
324
+ }