@tscircuit/schematic-trace-solver 0.0.10 → 0.0.11

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/dist/index.js CHANGED
@@ -6708,16 +6708,40 @@ var SchematicTraceSingleLineSolver = class extends BaseSolver {
6708
6708
  const startPin = this.pins.find(
6709
6709
  (pin) => Math.abs(pin.x - start.x) < 1e-10 && Math.abs(pin.y - start.y) < 1e-10
6710
6710
  );
6711
- if (startPin && !excludeChipIds.includes(startPin.chipId)) {
6712
- excludeChipIds.push(startPin.chipId);
6711
+ if (startPin) {
6712
+ const bounds = getInputChipBounds(this.chipMap[startPin.chipId]);
6713
+ const dx = end.x - start.x;
6714
+ const dy = end.y - start.y;
6715
+ const EPS = 1e-9;
6716
+ const onLeft = Math.abs(start.x - bounds.minX) < 1e-9;
6717
+ const onRight = Math.abs(start.x - bounds.maxX) < 1e-9;
6718
+ const onBottom = Math.abs(start.y - bounds.minY) < 1e-9;
6719
+ const onTop = Math.abs(start.y - bounds.maxY) < 1e-9;
6720
+ const entersInterior = onLeft && dx > EPS || onRight && dx < -EPS || onBottom && dy > EPS || onTop && dy < -EPS;
6721
+ if (entersInterior) return;
6722
+ if (!excludeChipIds.includes(startPin.chipId)) {
6723
+ excludeChipIds.push(startPin.chipId);
6724
+ }
6713
6725
  }
6714
6726
  }
6715
6727
  if (isEndPin) {
6716
6728
  const endPin = this.pins.find(
6717
6729
  (pin) => Math.abs(pin.x - end.x) < 1e-10 && Math.abs(pin.y - end.y) < 1e-10
6718
6730
  );
6719
- if (endPin && !excludeChipIds.includes(endPin.chipId)) {
6720
- excludeChipIds.push(endPin.chipId);
6731
+ if (endPin) {
6732
+ const bounds = getInputChipBounds(this.chipMap[endPin.chipId]);
6733
+ const dx = start.x - end.x;
6734
+ const dy = start.y - end.y;
6735
+ const EPS = 1e-9;
6736
+ const onLeft = Math.abs(end.x - bounds.minX) < 1e-9;
6737
+ const onRight = Math.abs(end.x - bounds.maxX) < 1e-9;
6738
+ const onBottom = Math.abs(end.y - bounds.minY) < 1e-9;
6739
+ const onTop = Math.abs(end.y - bounds.maxY) < 1e-9;
6740
+ const entersInterior = onLeft && dx > EPS || onRight && dx < -EPS || onBottom && dy > EPS || onTop && dy < -EPS;
6741
+ if (entersInterior) return;
6742
+ if (!excludeChipIds.includes(endPin.chipId)) {
6743
+ excludeChipIds.push(endPin.chipId);
6744
+ }
6721
6745
  }
6722
6746
  }
6723
6747
  const obstacleOps = { excludeChipIds };
@@ -13,6 +13,7 @@ import {
13
13
  } from "./generateElbowVariants"
14
14
  import type { Point } from "@tscircuit/math-utils"
15
15
  import { visualizeGuidelines } from "lib/solvers/GuidelinesSolver/visualizeGuidelines"
16
+ import { getInputChipBounds } from "lib/solvers/GuidelinesSolver/getInputChipBounds"
16
17
  import { getColorFromString } from "lib/utils/getColorFromString"
17
18
 
18
19
  export class SchematicTraceSingleLineSolver extends BaseSolver {
@@ -128,8 +129,25 @@ export class SchematicTraceSingleLineSolver extends BaseSolver {
128
129
  Math.abs(pin.x - start.x) < 1e-10 &&
129
130
  Math.abs(pin.y - start.y) < 1e-10,
130
131
  )
131
- if (startPin && !excludeChipIds.includes(startPin.chipId)) {
132
- excludeChipIds.push(startPin.chipId)
132
+ if (startPin) {
133
+ // Enforce that the first segment does not enter the chip interior.
134
+ const bounds = getInputChipBounds(this.chipMap[startPin.chipId])
135
+ const dx = end.x - start.x
136
+ const dy = end.y - start.y
137
+ const EPS = 1e-9
138
+ const onLeft = Math.abs(start.x - bounds.minX) < 1e-9
139
+ const onRight = Math.abs(start.x - bounds.maxX) < 1e-9
140
+ const onBottom = Math.abs(start.y - bounds.minY) < 1e-9
141
+ const onTop = Math.abs(start.y - bounds.maxY) < 1e-9
142
+ const entersInterior =
143
+ (onLeft && dx > EPS) ||
144
+ (onRight && dx < -EPS) ||
145
+ (onBottom && dy > EPS) ||
146
+ (onTop && dy < -EPS)
147
+ if (entersInterior) return
148
+ if (!excludeChipIds.includes(startPin.chipId)) {
149
+ excludeChipIds.push(startPin.chipId)
150
+ }
133
151
  }
134
152
  }
135
153
 
@@ -138,8 +156,25 @@ export class SchematicTraceSingleLineSolver extends BaseSolver {
138
156
  (pin) =>
139
157
  Math.abs(pin.x - end.x) < 1e-10 && Math.abs(pin.y - end.y) < 1e-10,
140
158
  )
141
- if (endPin && !excludeChipIds.includes(endPin.chipId)) {
142
- excludeChipIds.push(endPin.chipId)
159
+ if (endPin) {
160
+ // Enforce that the last segment approaches the pin from outside the chip.
161
+ const bounds = getInputChipBounds(this.chipMap[endPin.chipId])
162
+ const dx = start.x - end.x // vector from pin outward toward previous point
163
+ const dy = start.y - end.y
164
+ const EPS = 1e-9
165
+ const onLeft = Math.abs(end.x - bounds.minX) < 1e-9
166
+ const onRight = Math.abs(end.x - bounds.maxX) < 1e-9
167
+ const onBottom = Math.abs(end.y - bounds.minY) < 1e-9
168
+ const onTop = Math.abs(end.y - bounds.maxY) < 1e-9
169
+ const entersInterior =
170
+ (onLeft && dx > EPS) ||
171
+ (onRight && dx < -EPS) ||
172
+ (onBottom && dy > EPS) ||
173
+ (onTop && dy < -EPS)
174
+ if (entersInterior) return
175
+ if (!excludeChipIds.includes(endPin.chipId)) {
176
+ excludeChipIds.push(endPin.chipId)
177
+ }
143
178
  }
144
179
  }
145
180
 
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.10",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
@@ -0,0 +1,11 @@
1
+ import { useMemo } from "react"
2
+ import { GenericSolverDebugger } from "../components/GenericSolverDebugger"
3
+ import { SchematicTraceLinesSolver } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
4
+ import inputProblem from "./SchematicTraceLinesSolver02_params.json"
5
+
6
+ export default () => {
7
+ const solver = useMemo(() => {
8
+ return new SchematicTraceLinesSolver(inputProblem as any)
9
+ }, [])
10
+ return <GenericSolverDebugger solver={solver} />
11
+ }
@@ -0,0 +1,393 @@
1
+ {
2
+ "inputProblem": {
3
+ "chips": [
4
+ {
5
+ "chipId": "schematic_component_0",
6
+ "center": {
7
+ "x": 0,
8
+ "y": 0
9
+ },
10
+ "width": 1.8,
11
+ "height": 5,
12
+ "pins": [
13
+ {
14
+ "pinId": "U1.1",
15
+ "x": 0.9,
16
+ "y": 1.2
17
+ },
18
+ {
19
+ "pinId": "U1.2",
20
+ "x": 0.9,
21
+ "y": 0.3999999999999999
22
+ },
23
+ {
24
+ "pinId": "U1.3",
25
+ "x": 0.9,
26
+ "y": 0.5999999999999999
27
+ },
28
+ {
29
+ "pinId": "U1.4",
30
+ "x": -0.9,
31
+ "y": 0.3999999999999999
32
+ },
33
+ {
34
+ "pinId": "U1.5",
35
+ "x": 0.9,
36
+ "y": 0.9999999999999998
37
+ },
38
+ {
39
+ "pinId": "U1.6",
40
+ "x": 0.9,
41
+ "y": -0.19999999999999996
42
+ },
43
+ {
44
+ "pinId": "U1.7",
45
+ "x": -0.9,
46
+ "y": -0.7999999999999998
47
+ },
48
+ {
49
+ "pinId": "U1.9",
50
+ "x": 0.9,
51
+ "y": 0.19999999999999996
52
+ },
53
+ {
54
+ "pinId": "U1.10",
55
+ "x": 0.9,
56
+ "y": 0
57
+ },
58
+ {
59
+ "pinId": "U1.11",
60
+ "x": 0.9,
61
+ "y": 0.7999999999999998
62
+ },
63
+ {
64
+ "pinId": "U1.12",
65
+ "x": 0.9,
66
+ "y": -1.2
67
+ },
68
+ {
69
+ "pinId": "U1.13",
70
+ "x": 0.9,
71
+ "y": -1
72
+ },
73
+ {
74
+ "pinId": "U1.14",
75
+ "x": 0.9,
76
+ "y": -0.7999999999999999
77
+ },
78
+ {
79
+ "pinId": "U1.15",
80
+ "x": -0.9,
81
+ "y": 1
82
+ },
83
+ {
84
+ "pinId": "U1.16",
85
+ "x": -0.9,
86
+ "y": 1.2
87
+ },
88
+ {
89
+ "pinId": "U1.17",
90
+ "x": -0.9,
91
+ "y": 0.5999999999999999
92
+ },
93
+ {
94
+ "pinId": "U1.18",
95
+ "x": -0.9,
96
+ "y": -0.9999999999999998
97
+ },
98
+ {
99
+ "pinId": "U1.19",
100
+ "x": -0.9,
101
+ "y": -0.19999999999999996
102
+ },
103
+ {
104
+ "pinId": "U1.20",
105
+ "x": -0.9,
106
+ "y": 0.7999999999999999
107
+ },
108
+ {
109
+ "pinId": "U1.21",
110
+ "x": -0.9,
111
+ "y": -1.2
112
+ },
113
+ {
114
+ "pinId": "U1.22",
115
+ "x": 0.9,
116
+ "y": -0.5999999999999999
117
+ },
118
+ {
119
+ "pinId": "U1.23",
120
+ "x": 0.9,
121
+ "y": -0.3999999999999999
122
+ },
123
+ {
124
+ "pinId": "U1.25",
125
+ "x": -0.9,
126
+ "y": -0.5999999999999999
127
+ },
128
+ {
129
+ "pinId": "U1.26",
130
+ "x": -0.9,
131
+ "y": -0.3999999999999999
132
+ },
133
+ {
134
+ "pinId": "U1.27",
135
+ "x": -0.9,
136
+ "y": 0.19999999999999996
137
+ },
138
+ {
139
+ "pinId": "U1.28",
140
+ "x": -0.9,
141
+ "y": 0
142
+ }
143
+ ]
144
+ },
145
+ {
146
+ "chipId": "schematic_component_1",
147
+ "center": {
148
+ "x": 2,
149
+ "y": 1
150
+ },
151
+ "width": 1.0402490999999996,
152
+ "height": 0.5476905999999993,
153
+ "pins": [
154
+ {
155
+ "pinId": "LED1.1",
156
+ "x": 1.4798754500000002,
157
+ "y": 1.0005122999999987
158
+ },
159
+ {
160
+ "pinId": "LED1.2",
161
+ "x": 2.52012455,
162
+ "y": 0.9994877000000013
163
+ }
164
+ ]
165
+ }
166
+ ],
167
+ "directConnections": [
168
+ {
169
+ "pinIds": ["LED1.2", "U1.20"],
170
+ "netId": ".LED1 > port.right to .U1 > .pin20"
171
+ }
172
+ ],
173
+ "netConnections": [],
174
+ "availableNetLabelOrientations": {},
175
+ "maxMspPairDistance": 2
176
+ },
177
+ "chipMap": {
178
+ "schematic_component_0": {
179
+ "chipId": "schematic_component_0",
180
+ "center": {
181
+ "x": 0,
182
+ "y": 0
183
+ },
184
+ "width": 1.8,
185
+ "height": 5,
186
+ "pins": [
187
+ {
188
+ "pinId": "U1.1",
189
+ "x": 0.9,
190
+ "y": 1.2
191
+ },
192
+ {
193
+ "pinId": "U1.2",
194
+ "x": 0.9,
195
+ "y": 0.3999999999999999
196
+ },
197
+ {
198
+ "pinId": "U1.3",
199
+ "x": 0.9,
200
+ "y": 0.5999999999999999
201
+ },
202
+ {
203
+ "pinId": "U1.4",
204
+ "x": -0.9,
205
+ "y": 0.3999999999999999
206
+ },
207
+ {
208
+ "pinId": "U1.5",
209
+ "x": 0.9,
210
+ "y": 0.9999999999999998
211
+ },
212
+ {
213
+ "pinId": "U1.6",
214
+ "x": 0.9,
215
+ "y": -0.19999999999999996
216
+ },
217
+ {
218
+ "pinId": "U1.7",
219
+ "x": -0.9,
220
+ "y": -0.7999999999999998
221
+ },
222
+ {
223
+ "pinId": "U1.9",
224
+ "x": 0.9,
225
+ "y": 0.19999999999999996
226
+ },
227
+ {
228
+ "pinId": "U1.10",
229
+ "x": 0.9,
230
+ "y": 0
231
+ },
232
+ {
233
+ "pinId": "U1.11",
234
+ "x": 0.9,
235
+ "y": 0.7999999999999998
236
+ },
237
+ {
238
+ "pinId": "U1.12",
239
+ "x": 0.9,
240
+ "y": -1.2
241
+ },
242
+ {
243
+ "pinId": "U1.13",
244
+ "x": 0.9,
245
+ "y": -1
246
+ },
247
+ {
248
+ "pinId": "U1.14",
249
+ "x": 0.9,
250
+ "y": -0.7999999999999999
251
+ },
252
+ {
253
+ "pinId": "U1.15",
254
+ "x": -0.9,
255
+ "y": 1
256
+ },
257
+ {
258
+ "pinId": "U1.16",
259
+ "x": -0.9,
260
+ "y": 1.2
261
+ },
262
+ {
263
+ "pinId": "U1.17",
264
+ "x": -0.9,
265
+ "y": 0.5999999999999999
266
+ },
267
+ {
268
+ "pinId": "U1.18",
269
+ "x": -0.9,
270
+ "y": -0.9999999999999998
271
+ },
272
+ {
273
+ "pinId": "U1.19",
274
+ "x": -0.9,
275
+ "y": -0.19999999999999996
276
+ },
277
+ {
278
+ "pinId": "U1.20",
279
+ "x": -0.9,
280
+ "y": 0.7999999999999999
281
+ },
282
+ {
283
+ "pinId": "U1.21",
284
+ "x": -0.9,
285
+ "y": -1.2
286
+ },
287
+ {
288
+ "pinId": "U1.22",
289
+ "x": 0.9,
290
+ "y": -0.5999999999999999
291
+ },
292
+ {
293
+ "pinId": "U1.23",
294
+ "x": 0.9,
295
+ "y": -0.3999999999999999
296
+ },
297
+ {
298
+ "pinId": "U1.25",
299
+ "x": -0.9,
300
+ "y": -0.5999999999999999
301
+ },
302
+ {
303
+ "pinId": "U1.26",
304
+ "x": -0.9,
305
+ "y": -0.3999999999999999
306
+ },
307
+ {
308
+ "pinId": "U1.27",
309
+ "x": -0.9,
310
+ "y": 0.19999999999999996
311
+ },
312
+ {
313
+ "pinId": "U1.28",
314
+ "x": -0.9,
315
+ "y": 0
316
+ }
317
+ ]
318
+ },
319
+ "schematic_component_1": {
320
+ "chipId": "schematic_component_1",
321
+ "center": {
322
+ "x": 2,
323
+ "y": 1
324
+ },
325
+ "width": 1.0402490999999996,
326
+ "height": 0.5476905999999993,
327
+ "pins": [
328
+ {
329
+ "pinId": "LED1.1",
330
+ "x": 1.4798754500000002,
331
+ "y": 1.0005122999999987
332
+ },
333
+ {
334
+ "pinId": "LED1.2",
335
+ "x": 2.52012455,
336
+ "y": 0.9994877000000013
337
+ }
338
+ ]
339
+ }
340
+ },
341
+ "mspConnectionPairs": [
342
+ {
343
+ "mspPairId": "LED1.2-U1.20",
344
+ "dcConnNetId": "connectivity_net0",
345
+ "globalConnNetId": "connectivity_net0",
346
+ "userNetId": ".LED1 > port.right to .U1 > .pin20",
347
+ "pins": [
348
+ {
349
+ "pinId": "LED1.2",
350
+ "x": 2.52012455,
351
+ "y": 0.9994877000000013,
352
+ "_facingDirection": "x+",
353
+ "chipId": "schematic_component_1"
354
+ },
355
+ {
356
+ "pinId": "U1.20",
357
+ "x": -0.9,
358
+ "y": 0.7999999999999999,
359
+ "_facingDirection": "x-",
360
+ "chipId": "schematic_component_0"
361
+ }
362
+ ]
363
+ }
364
+ ],
365
+ "dcConnMap": {
366
+ "netMap": {
367
+ "connectivity_net0": ["LED1.2", "U1.20"]
368
+ },
369
+ "idToNetMap": {
370
+ "LED1.2": "connectivity_net0",
371
+ "U1.20": "connectivity_net0"
372
+ }
373
+ },
374
+ "globalConnMap": {
375
+ "netMap": {
376
+ "connectivity_net0": ["LED1.2", "U1.20"]
377
+ },
378
+ "idToNetMap": {
379
+ "LED1.2": "connectivity_net0",
380
+ "U1.20": "connectivity_net0"
381
+ }
382
+ },
383
+ "guidelines": [
384
+ {
385
+ "orientation": "horizontal",
386
+ "y": 1
387
+ },
388
+ {
389
+ "orientation": "vertical",
390
+ "x": 1.189937725
391
+ }
392
+ ]
393
+ }
@@ -0,0 +1,182 @@
1
+ import type { InputProblem } from "lib/index"
2
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
3
+
4
+ const inputProblem: InputProblem = {
5
+ chips: [
6
+ {
7
+ chipId: "schematic_component_0",
8
+ center: {
9
+ x: 0,
10
+ y: 0,
11
+ },
12
+ width: 1,
13
+ height: 5,
14
+ pins: [
15
+ {
16
+ pinId: "U1.1",
17
+ x: 0.9,
18
+ y: 1.2,
19
+ },
20
+ {
21
+ pinId: "U1.2",
22
+ x: 0.9,
23
+ y: 0.3999999999999999,
24
+ },
25
+ {
26
+ pinId: "U1.3",
27
+ x: 0.9,
28
+ y: 0.5999999999999999,
29
+ },
30
+ {
31
+ pinId: "U1.4",
32
+ x: -0.9,
33
+ y: 0.3999999999999999,
34
+ },
35
+ {
36
+ pinId: "U1.5",
37
+ x: 0.9,
38
+ y: 0.9999999999999998,
39
+ },
40
+ {
41
+ pinId: "U1.6",
42
+ x: 0.9,
43
+ y: -0.19999999999999996,
44
+ },
45
+ {
46
+ pinId: "U1.7",
47
+ x: -0.9,
48
+ y: -0.7999999999999998,
49
+ },
50
+ {
51
+ pinId: "U1.9",
52
+ x: 0.9,
53
+ y: 0.19999999999999996,
54
+ },
55
+ {
56
+ pinId: "U1.10",
57
+ x: 0.9,
58
+ y: 0,
59
+ },
60
+ {
61
+ pinId: "U1.11",
62
+ x: 0.9,
63
+ y: 0.7999999999999998,
64
+ },
65
+ {
66
+ pinId: "U1.12",
67
+ x: 0.9,
68
+ y: -1.2,
69
+ },
70
+ {
71
+ pinId: "U1.13",
72
+ x: 0.9,
73
+ y: -1,
74
+ },
75
+ {
76
+ pinId: "U1.14",
77
+ x: 0.9,
78
+ y: -0.7999999999999999,
79
+ },
80
+ {
81
+ pinId: "U1.15",
82
+ x: -0.9,
83
+ y: 1,
84
+ },
85
+ {
86
+ pinId: "U1.16",
87
+ x: -0.9,
88
+ y: 1.2,
89
+ },
90
+ {
91
+ pinId: "U1.17",
92
+ x: -0.9,
93
+ y: 0.5999999999999999,
94
+ },
95
+ {
96
+ pinId: "U1.18",
97
+ x: -0.9,
98
+ y: -0.9999999999999998,
99
+ },
100
+ {
101
+ pinId: "U1.19",
102
+ x: -0.9,
103
+ y: -0.19999999999999996,
104
+ },
105
+ {
106
+ pinId: "U1.20",
107
+ x: -0.9,
108
+ y: 0.7999999999999999,
109
+ },
110
+ {
111
+ pinId: "U1.21",
112
+ x: -0.9,
113
+ y: -1.2,
114
+ },
115
+ {
116
+ pinId: "U1.22",
117
+ x: 0.9,
118
+ y: -0.5999999999999999,
119
+ },
120
+ {
121
+ pinId: "U1.23",
122
+ x: 0.9,
123
+ y: -0.3999999999999999,
124
+ },
125
+ {
126
+ pinId: "U1.25",
127
+ x: -0.9,
128
+ y: -0.5999999999999999,
129
+ },
130
+ {
131
+ pinId: "U1.26",
132
+ x: -0.9,
133
+ y: -0.3999999999999999,
134
+ },
135
+ {
136
+ pinId: "U1.27",
137
+ x: -0.9,
138
+ y: 0.19999999999999996,
139
+ },
140
+ {
141
+ pinId: "U1.28",
142
+ x: -0.9,
143
+ y: 0,
144
+ },
145
+ ],
146
+ },
147
+ {
148
+ chipId: "schematic_component_1",
149
+ center: {
150
+ x: 2,
151
+ y: 1,
152
+ },
153
+ width: 1.0402490999999996,
154
+ height: 0.5476905999999993,
155
+ pins: [
156
+ {
157
+ pinId: "LED1.1",
158
+ x: 1.4808529,
159
+ y: 1.0005122999999987,
160
+ },
161
+ {
162
+ pinId: "LED1.2",
163
+ x: 2.5191471,
164
+ y: 0.9994877000000013,
165
+ },
166
+ ],
167
+ },
168
+ ],
169
+ directConnections: [
170
+ {
171
+ pinIds: ["LED1.2", "U1.20"],
172
+ netId: ".LED1 > port.right to .U1 > .pin20",
173
+ },
174
+ ],
175
+ netConnections: [],
176
+ availableNetLabelOrientations: {},
177
+ maxMspPairDistance: 2,
178
+ }
179
+
180
+ export default function Example05Page() {
181
+ return <PipelineDebugger inputProblem={inputProblem} />
182
+ }