@tscircuit/schematic-trace-solver 0.0.75 → 0.0.77

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
@@ -357,6 +357,16 @@ ${pin._facingDirection ?? getPinDirection(pin, chip)}`,
357
357
  });
358
358
  }
359
359
  }
360
+ for (const textBox of inputProblem.textBoxes ?? []) {
361
+ graphics.rects.push({
362
+ label: textBox.text ?? "schematic_text",
363
+ center: textBox.center,
364
+ width: textBox.width,
365
+ height: textBox.height,
366
+ fill: "rgba(160, 0, 220, 0.14)",
367
+ strokeColor: "rgba(160, 0, 220, 0.9)"
368
+ });
369
+ }
360
370
  for (const directConn of inputProblem.directConnections) {
361
371
  const [pinId1, pinId2] = directConn.pinIds;
362
372
  const pin1 = pinIdMap.get(pinId1);
@@ -6902,6 +6912,58 @@ var VccNetLabelCornerPlacementSolver = class extends BaseSolver {
6902
6912
  }
6903
6913
  };
6904
6914
 
6915
+ // lib/utils/dedupeOrientations.ts
6916
+ var dedupeOrientations = (orientations) => [
6917
+ ...new Set(orientations)
6918
+ ];
6919
+
6920
+ // lib/utils/dedupeStrings.ts
6921
+ var dedupeStrings = (values) => [
6922
+ ...new Set(values.filter((value) => value !== void 0))
6923
+ ];
6924
+
6925
+ // lib/utils/getOrientationConstraintKeys.ts
6926
+ var getOrientationConstraintKeys = (inputProblem, label) => dedupeStrings([
6927
+ label.netId,
6928
+ label.globalConnNetId,
6929
+ ...inputProblem.netConnections.filter(
6930
+ (connection) => label.pinIds.some((pinId) => connection.pinIds.includes(pinId))
6931
+ ).map((connection) => connection.netId)
6932
+ ]);
6933
+
6934
+ // lib/utils/normalizeFacingDirection.ts
6935
+ var normalizeFacingDirection = (value) => {
6936
+ switch (value) {
6937
+ case "x+":
6938
+ case "+x":
6939
+ return "x+";
6940
+ case "x-":
6941
+ case "-x":
6942
+ return "x-";
6943
+ case "y+":
6944
+ case "+y":
6945
+ return "y+";
6946
+ case "y-":
6947
+ case "-y":
6948
+ return "y-";
6949
+ }
6950
+ };
6951
+
6952
+ // lib/utils/getOrientationConstraint.ts
6953
+ var getOrientationConstraint = (inputProblem, label) => {
6954
+ const availableOrientations = inputProblem.availableNetLabelOrientations ?? {};
6955
+ for (const netId of getOrientationConstraintKeys(inputProblem, label)) {
6956
+ if (Object.hasOwn(availableOrientations, netId)) {
6957
+ return dedupeOrientations(
6958
+ (availableOrientations[netId] ?? []).map(normalizeFacingDirection).filter(
6959
+ (orientation) => orientation !== void 0
6960
+ )
6961
+ );
6962
+ }
6963
+ }
6964
+ return null;
6965
+ };
6966
+
6905
6967
  // lib/solvers/TraceAnchoredNetLabelOverlapSolver/geometry.ts
6906
6968
  var EPS10 = 1e-6;
6907
6969
  var TRACE_BOUNDARY_TOLERANCE2 = 1e-6;
@@ -7128,26 +7190,6 @@ var createCandidate = (params) => {
7128
7190
  selected: false
7129
7191
  };
7130
7192
  };
7131
- var getOrientationConstraint = (inputProblem, label) => {
7132
- const availableOrientations = inputProblem.availableNetLabelOrientations ?? {};
7133
- for (const netId of getOrientationConstraintKeys(inputProblem, label)) {
7134
- if (Object.hasOwn(availableOrientations, netId)) {
7135
- return dedupeOrientations(
7136
- (availableOrientations[netId] ?? []).map(normalizeFacingDirection).filter(
7137
- (orientation) => orientation !== void 0
7138
- )
7139
- );
7140
- }
7141
- }
7142
- return null;
7143
- };
7144
- var getOrientationConstraintKeys = (inputProblem, label) => dedupeStrings([
7145
- label.netId,
7146
- label.globalConnNetId,
7147
- ...inputProblem.netConnections.filter(
7148
- (connection) => label.pinIds.some((pinId) => connection.pinIds.includes(pinId))
7149
- ).map((connection) => connection.netId)
7150
- ]);
7151
7193
  var getUnconstrainedOrientations = (params) => {
7152
7194
  const { label, inputProblem, point } = params;
7153
7195
  return dedupeOrientations([
@@ -7286,28 +7328,6 @@ var getNetLabelHeight = (inputProblem, label) => {
7286
7328
  )?.netLabelHeight;
7287
7329
  };
7288
7330
  var roundDistance = (distance3) => Number(distance3.toFixed(6));
7289
- var dedupeOrientations = (orientations) => [
7290
- ...new Set(orientations)
7291
- ];
7292
- var normalizeFacingDirection = (value) => {
7293
- switch (value) {
7294
- case "x+":
7295
- case "+x":
7296
- return "x+";
7297
- case "x-":
7298
- case "-x":
7299
- return "x-";
7300
- case "y+":
7301
- case "+y":
7302
- return "y+";
7303
- case "y-":
7304
- case "-y":
7305
- return "y-";
7306
- }
7307
- };
7308
- var dedupeStrings = (values) => [
7309
- ...new Set(values.filter((value) => value !== void 0))
7310
- ];
7311
7331
  var isSamePlacement = (label, point, orientation) => Math.abs(point.x - label.anchorPoint.x) <= EPS10 && Math.abs(point.y - label.anchorPoint.y) <= EPS10 && orientation === label.orientation;
7312
7332
 
7313
7333
  // lib/solvers/TraceAnchoredNetLabelOverlapSolver/visualize.ts
@@ -47,6 +47,17 @@ export const visualizeInputProblem = (
47
47
  }
48
48
  }
49
49
 
50
+ for (const textBox of inputProblem.textBoxes ?? []) {
51
+ graphics.rects.push({
52
+ label: textBox.text ?? "schematic_text",
53
+ center: textBox.center,
54
+ width: textBox.width,
55
+ height: textBox.height,
56
+ fill: "rgba(160, 0, 220, 0.14)",
57
+ strokeColor: "rgba(160, 0, 220, 0.9)",
58
+ } as any)
59
+ }
60
+
50
61
  for (const directConn of inputProblem.directConnections) {
51
62
  const [pinId1, pinId2] = directConn.pinIds
52
63
  const pin1 = pinIdMap.get(pinId1)!
@@ -5,7 +5,9 @@ import {
5
5
  } from "lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/geometry"
6
6
  import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
7
7
  import type { InputProblem } from "lib/types/InputProblem"
8
+ import { dedupeOrientations } from "lib/utils/dedupeOrientations"
8
9
  import type { FacingDirection } from "lib/utils/dir"
10
+ import { getOrientationConstraint } from "lib/utils/getOrientationConstraint"
9
11
  import {
10
12
  EPS,
11
13
  getManhattanDistance,
@@ -145,41 +147,6 @@ const createCandidate = (params: {
145
147
  }
146
148
  }
147
149
 
148
- const getOrientationConstraint = (
149
- inputProblem: InputProblem,
150
- label: NetLabelPlacement,
151
- ): FacingDirection[] | null => {
152
- const availableOrientations = inputProblem.availableNetLabelOrientations ?? {}
153
- for (const netId of getOrientationConstraintKeys(inputProblem, label)) {
154
- if (Object.hasOwn(availableOrientations, netId)) {
155
- return dedupeOrientations(
156
- (availableOrientations[netId] ?? [])
157
- .map(normalizeFacingDirection)
158
- .filter(
159
- (orientation): orientation is FacingDirection =>
160
- orientation !== undefined,
161
- ),
162
- )
163
- }
164
- }
165
-
166
- return null
167
- }
168
-
169
- const getOrientationConstraintKeys = (
170
- inputProblem: InputProblem,
171
- label: NetLabelPlacement,
172
- ) =>
173
- dedupeStrings([
174
- label.netId,
175
- label.globalConnNetId,
176
- ...inputProblem.netConnections
177
- .filter((connection) =>
178
- label.pinIds.some((pinId) => connection.pinIds.includes(pinId)),
179
- )
180
- .map((connection) => connection.netId),
181
- ])
182
-
183
150
  const getUnconstrainedOrientations = (params: {
184
151
  label: NetLabelPlacement
185
152
  inputProblem: InputProblem
@@ -381,33 +348,6 @@ const getNetLabelHeight = (
381
348
 
382
349
  const roundDistance = (distance: number) => Number(distance.toFixed(6))
383
350
 
384
- const dedupeOrientations = (orientations: FacingDirection[]) => [
385
- ...new Set(orientations),
386
- ]
387
-
388
- const normalizeFacingDirection = (
389
- value: string,
390
- ): FacingDirection | undefined => {
391
- switch (value) {
392
- case "x+":
393
- case "+x":
394
- return "x+"
395
- case "x-":
396
- case "-x":
397
- return "x-"
398
- case "y+":
399
- case "+y":
400
- return "y+"
401
- case "y-":
402
- case "-y":
403
- return "y-"
404
- }
405
- }
406
-
407
- const dedupeStrings = (values: Array<string | undefined>) => [
408
- ...new Set(values.filter((value): value is string => value !== undefined)),
409
- ]
410
-
411
351
  const isSamePlacement = (
412
352
  label: NetLabelPlacement,
413
353
  point: Point,
@@ -0,0 +1,5 @@
1
+ import type { FacingDirection } from "./dir"
2
+
3
+ export const dedupeOrientations = (orientations: FacingDirection[]) => [
4
+ ...new Set(orientations),
5
+ ]
@@ -0,0 +1,3 @@
1
+ export const dedupeStrings = (values: Array<string | undefined>) => [
2
+ ...new Set(values.filter((value): value is string => value !== undefined)),
3
+ ]
@@ -0,0 +1,27 @@
1
+ import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
2
+ import type { InputProblem } from "lib/types/InputProblem"
3
+ import { dedupeOrientations } from "./dedupeOrientations"
4
+ import type { FacingDirection } from "./dir"
5
+ import { getOrientationConstraintKeys } from "./getOrientationConstraintKeys"
6
+ import { normalizeFacingDirection } from "./normalizeFacingDirection"
7
+
8
+ export const getOrientationConstraint = (
9
+ inputProblem: InputProblem,
10
+ label: NetLabelPlacement,
11
+ ): FacingDirection[] | null => {
12
+ const availableOrientations = inputProblem.availableNetLabelOrientations ?? {}
13
+ for (const netId of getOrientationConstraintKeys(inputProblem, label)) {
14
+ if (Object.hasOwn(availableOrientations, netId)) {
15
+ return dedupeOrientations(
16
+ (availableOrientations[netId] ?? [])
17
+ .map(normalizeFacingDirection)
18
+ .filter(
19
+ (orientation): orientation is FacingDirection =>
20
+ orientation !== undefined,
21
+ ),
22
+ )
23
+ }
24
+ }
25
+
26
+ return null
27
+ }
@@ -0,0 +1,17 @@
1
+ import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
2
+ import type { InputProblem } from "lib/types/InputProblem"
3
+ import { dedupeStrings } from "./dedupeStrings"
4
+
5
+ export const getOrientationConstraintKeys = (
6
+ inputProblem: InputProblem,
7
+ label: NetLabelPlacement,
8
+ ) =>
9
+ dedupeStrings([
10
+ label.netId,
11
+ label.globalConnNetId,
12
+ ...inputProblem.netConnections
13
+ .filter((connection) =>
14
+ label.pinIds.some((pinId) => connection.pinIds.includes(pinId)),
15
+ )
16
+ .map((connection) => connection.netId),
17
+ ])
@@ -0,0 +1,20 @@
1
+ import type { FacingDirection } from "./dir"
2
+
3
+ export const normalizeFacingDirection = (
4
+ value: string,
5
+ ): FacingDirection | undefined => {
6
+ switch (value) {
7
+ case "x+":
8
+ case "+x":
9
+ return "x+"
10
+ case "x-":
11
+ case "-x":
12
+ return "x-"
13
+ case "y+":
14
+ case "+y":
15
+ return "y+"
16
+ case "y-":
17
+ case "-y":
18
+ return "y-"
19
+ }
20
+ }
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.75",
4
+ "version": "0.0.77",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
@@ -0,0 +1,4 @@
1
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
2
+ import inputProblem from "../../tests/assets/example44.json"
3
+
4
+ export default () => <PipelineDebugger inputProblem={inputProblem as any} />
@@ -0,0 +1,4 @@
1
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
2
+ import inputProblem from "../../tests/assets/example45.json"
3
+
4
+ export default () => <PipelineDebugger inputProblem={inputProblem as any} />
@@ -0,0 +1,217 @@
1
+ {
2
+ "chips": [
3
+ {
4
+ "chipId": "schematic_component_0",
5
+ "center": {
6
+ "x": 0,
7
+ "y": 0
8
+ },
9
+ "width": 1.3,
10
+ "height": 1,
11
+ "pins": [
12
+ {
13
+ "pinId": "PWR1.7",
14
+ "x": 1.05,
15
+ "y": 0.2
16
+ },
17
+ {
18
+ "pinId": "PWR1.6",
19
+ "x": 1.05,
20
+ "y": 0
21
+ },
22
+ {
23
+ "pinId": "PWR1.5",
24
+ "x": 1.05,
25
+ "y": -0.2
26
+ },
27
+ {
28
+ "pinId": "PWR1.4",
29
+ "x": -1.05,
30
+ "y": -0.30000000000000004
31
+ },
32
+ {
33
+ "pinId": "PWR1.3",
34
+ "x": -1.05,
35
+ "y": -0.09999999999999998
36
+ },
37
+ {
38
+ "pinId": "PWR1.2",
39
+ "x": -1.05,
40
+ "y": 0.10000000000000003
41
+ },
42
+ {
43
+ "pinId": "PWR1.1",
44
+ "x": -1.05,
45
+ "y": 0.30000000000000004
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "chipId": "schematic_component_1",
51
+ "center": {
52
+ "x": -3,
53
+ "y": 0
54
+ },
55
+ "width": 1.0999999999999996,
56
+ "height": 0.778910699999999,
57
+ "pins": [
58
+ {
59
+ "pinId": "R6.1",
60
+ "x": -3.55,
61
+ "y": 0
62
+ },
63
+ {
64
+ "pinId": "R6.2",
65
+ "x": -2.45,
66
+ "y": 0
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "chipId": "schematic_component_2",
72
+ "center": {
73
+ "x": -3,
74
+ "y": -2
75
+ },
76
+ "width": 1.0999999999999996,
77
+ "height": 0.7789106999999988,
78
+ "pins": [
79
+ {
80
+ "pinId": "R7.1",
81
+ "x": -3.55,
82
+ "y": -1.9999999999999998
83
+ },
84
+ {
85
+ "pinId": "R7.2",
86
+ "x": -2.45,
87
+ "y": -1.9999999999999998
88
+ }
89
+ ]
90
+ },
91
+ {
92
+ "chipId": "schematic_component_3",
93
+ "center": {
94
+ "x": -3,
95
+ "y": 2
96
+ },
97
+ "width": 1.0999999999999996,
98
+ "height": 0.7789106999999988,
99
+ "pins": [
100
+ {
101
+ "pinId": "R8.1",
102
+ "x": -3.55,
103
+ "y": 2
104
+ },
105
+ {
106
+ "pinId": "R8.2",
107
+ "x": -2.45,
108
+ "y": 2
109
+ }
110
+ ]
111
+ },
112
+ {
113
+ "chipId": "schematic_component_4",
114
+ "center": {
115
+ "x": 3,
116
+ "y": -1.5
117
+ },
118
+ "width": 1.0999999999999996,
119
+ "height": 1.2400000000000002,
120
+ "pins": [
121
+ {
122
+ "pinId": "C6.1",
123
+ "x": 2.45,
124
+ "y": -1.5
125
+ },
126
+ {
127
+ "pinId": "C6.2",
128
+ "x": 3.55,
129
+ "y": -1.5
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ "chipId": "schematic_component_5",
135
+ "center": {
136
+ "x": 3,
137
+ "y": 0
138
+ },
139
+ "width": 1.0999999999999996,
140
+ "height": 1.24,
141
+ "pins": [
142
+ {
143
+ "pinId": "C7.1",
144
+ "x": 2.45,
145
+ "y": 0
146
+ },
147
+ {
148
+ "pinId": "C7.2",
149
+ "x": 3.55,
150
+ "y": 0
151
+ }
152
+ ]
153
+ },
154
+ {
155
+ "chipId": "schematic_component_6",
156
+ "center": {
157
+ "x": 4,
158
+ "y": 3.1325000000000003
159
+ },
160
+ "width": 1.1299999999999994,
161
+ "height": 0.9150000000000005,
162
+ "pins": [
163
+ {
164
+ "pinId": "LED1.1",
165
+ "x": 3.46,
166
+ "y": 3
167
+ },
168
+ {
169
+ "pinId": "LED1.2",
170
+ "x": 4.54,
171
+ "y": 3
172
+ }
173
+ ]
174
+ }
175
+ ],
176
+ "directConnections": [
177
+ {
178
+ "pinIds": ["R6.1", "PWR1.1"],
179
+ "netId": ".R6 > .pin1 to .PWR1 > .OUT"
180
+ },
181
+ {
182
+ "pinIds": ["LED1.1", "R8.2"],
183
+ "netId": ".LED1 > .pos to .R8 > .pin2"
184
+ },
185
+ {
186
+ "pinIds": ["PWR1.2", "R6.2"],
187
+ "netId": ".PWR1 > .FB to .R6 > .pin2"
188
+ },
189
+ {
190
+ "pinIds": ["PWR1.2", "R7.1"],
191
+ "netId": ".PWR1 > .FB to .R7 > .pin1"
192
+ }
193
+ ],
194
+ "netConnections": [
195
+ {
196
+ "netId": "gnd",
197
+ "pinIds": ["PWR1.7", "PWR1.3", "R7.2", "C6.2", "C7.2", "LED1.2"],
198
+ "netLabelWidth": 0.48
199
+ },
200
+ {
201
+ "netId": "v5",
202
+ "pinIds": ["PWR1.6", "PWR1.4", "C6.1"],
203
+ "netLabelWidth": 0.36
204
+ },
205
+ {
206
+ "netId": "v3_3",
207
+ "pinIds": ["PWR1.1", "R6.1", "R8.1", "C7.1"],
208
+ "netLabelWidth": 0.6
209
+ }
210
+ ],
211
+ "availableNetLabelOrientations": {
212
+ "v5": ["y+"],
213
+ "v3_3": ["y+"],
214
+ "gnd": ["y-"]
215
+ },
216
+ "maxMspPairDistance": 2.4
217
+ }
@@ -0,0 +1,121 @@
1
+ {
2
+ "chips": [
3
+ {
4
+ "chipId": "schematic_component_0",
5
+ "center": {
6
+ "x": 7,
7
+ "y": 0.7
8
+ },
9
+ "width": 1,
10
+ "height": 1,
11
+ "pins": [
12
+ {
13
+ "pinId": "IC2.15",
14
+ "x": 7.9,
15
+ "y": 0.7
16
+ }
17
+ ],
18
+ "sectionId": "mcu"
19
+ },
20
+ {
21
+ "chipId": "schematic_component_19",
22
+ "center": {
23
+ "x": 11.8,
24
+ "y": 0.19999999999999998
25
+ },
26
+ "width": 0.7699999999999996,
27
+ "height": 1,
28
+ "pins": [
29
+ {
30
+ "pinId": "CONN1.1",
31
+ "x": 11.015,
32
+ "y": 0.5
33
+ },
34
+ {
35
+ "pinId": "CONN1.2",
36
+ "x": 11.015,
37
+ "y": 0.30000000000000004
38
+ },
39
+ {
40
+ "pinId": "CONN1.3",
41
+ "x": 11.015,
42
+ "y": 0.10000000000000003
43
+ },
44
+ {
45
+ "pinId": "CONN1.4",
46
+ "x": 11.015,
47
+ "y": -0.10000000000000003
48
+ }
49
+ ],
50
+ "sectionId": "i2c"
51
+ },
52
+ {
53
+ "chipId": "schematic_component_20",
54
+ "center": {
55
+ "x": 9.6,
56
+ "y": 0.7
57
+ },
58
+ "width": 1.1000000000000014,
59
+ "height": 0.7789106999999991,
60
+ "pins": [
61
+ {
62
+ "pinId": "R10.1",
63
+ "x": 9.05,
64
+ "y": 0.7
65
+ },
66
+ {
67
+ "pinId": "R10.2",
68
+ "x": 10.15,
69
+ "y": 0.7
70
+ }
71
+ ],
72
+ "sectionId": "i2c"
73
+ },
74
+ {
75
+ "chipId": "schematic_component_21",
76
+ "center": {
77
+ "x": 9.6,
78
+ "y": -0.3
79
+ },
80
+ "width": 1.1000000000000014,
81
+ "height": 0.7789106999999987,
82
+ "pins": [
83
+ {
84
+ "pinId": "R11.1",
85
+ "x": 9.05,
86
+ "y": -0.3
87
+ },
88
+ {
89
+ "pinId": "R11.2",
90
+ "x": 10.15,
91
+ "y": -0.3
92
+ }
93
+ ],
94
+ "sectionId": "i2c"
95
+ }
96
+ ],
97
+ "directConnections": [],
98
+ "netConnections": [
99
+ {
100
+ "netId": "V3V3",
101
+ "pinIds": ["CONN1.2", "R10.1", "R11.1"],
102
+ "netLabelWidth": 0.6
103
+ },
104
+ {
105
+ "netId": "SDA",
106
+ "pinIds": ["IC2.15", "CONN1.3", "R10.2"],
107
+ "netLabelWidth": 0.48
108
+ },
109
+ {
110
+ "netId": "SCL",
111
+ "pinIds": ["CONN1.4", "R11.2"],
112
+ "netLabelWidth": 0.48
113
+ }
114
+ ],
115
+ "availableNetLabelOrientations": {
116
+ "V3V3": ["y+"],
117
+ "SDA": ["x-", "x+"],
118
+ "SCL": ["x-", "x+"]
119
+ },
120
+ "maxMspPairDistance": 2.4
121
+ }