@tscircuit/schematic-trace-solver 0.0.132 → 0.0.134
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 +265 -134
- package/lib/solvers/AvailableNetOrientationSolver/AvailableNetOrientationSolver.ts +12 -6
- package/lib/solvers/AvailableNetOrientationSolver/orderRoutedLabelsBeforeOverlappingPortLabels.ts +47 -0
- package/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts +140 -6
- package/package.json +1 -1
- package/tests/repros/__snapshots__/repro-type-c-vbus-led-ground-label.snap.svg +66 -0
- package/tests/repros/__snapshots__/repro-usb-power-vbus-label-detour.snap.svg +3 -3
- package/tests/repros/repro-type-c-vbus-led-ground-label.test.ts +149 -0
- package/tests/repros/repro-usb-power-vbus-label-detour.test.ts +20 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
|
|
3
|
+
import type { InputProblem } from "lib/types/InputProblem"
|
|
4
|
+
import "tests/fixtures/matcher"
|
|
5
|
+
|
|
6
|
+
const connectorPins = [
|
|
7
|
+
"VBUS1",
|
|
8
|
+
"VBUS2",
|
|
9
|
+
"CC1",
|
|
10
|
+
"CC2",
|
|
11
|
+
"DP1",
|
|
12
|
+
"DP2",
|
|
13
|
+
"DM1",
|
|
14
|
+
"DM2",
|
|
15
|
+
"SBU1",
|
|
16
|
+
"SBU2",
|
|
17
|
+
"GND1",
|
|
18
|
+
"GND2",
|
|
19
|
+
].map((name, index) => ({
|
|
20
|
+
pinId: `J1.${name}`,
|
|
21
|
+
x: -1.7,
|
|
22
|
+
y: 1.65 - index * 0.3,
|
|
23
|
+
_facingDirection: "x+" as const,
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
// Reproduces a TYPE-C-31-M-12 connector with its two VBUS pins joined to a
|
|
27
|
+
// resistor/LED chain while the LED cathode shares the connector's GND net.
|
|
28
|
+
// The distant GND endpoints should be represented by separate net labels.
|
|
29
|
+
const inputProblem: InputProblem = {
|
|
30
|
+
chips: [
|
|
31
|
+
{
|
|
32
|
+
chipId: "J1",
|
|
33
|
+
center: { x: -3, y: 0 },
|
|
34
|
+
width: 2.6,
|
|
35
|
+
height: 4,
|
|
36
|
+
pins: connectorPins,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
chipId: "R1",
|
|
40
|
+
center: { x: 0, y: 1.5 },
|
|
41
|
+
width: 0.8,
|
|
42
|
+
height: 0.5,
|
|
43
|
+
pins: [
|
|
44
|
+
{
|
|
45
|
+
pinId: "R1.1",
|
|
46
|
+
x: -0.4,
|
|
47
|
+
y: 1.5,
|
|
48
|
+
_facingDirection: "x-",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
pinId: "R1.2",
|
|
52
|
+
x: 0.4,
|
|
53
|
+
y: 1.5,
|
|
54
|
+
_facingDirection: "x+",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
chipId: "D1",
|
|
60
|
+
center: { x: 3, y: 1.5 },
|
|
61
|
+
width: 1,
|
|
62
|
+
height: 0.8,
|
|
63
|
+
pins: [
|
|
64
|
+
{
|
|
65
|
+
pinId: "D1.1",
|
|
66
|
+
x: 2.5,
|
|
67
|
+
y: 1.5,
|
|
68
|
+
_facingDirection: "x-",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
pinId: "D1.2",
|
|
72
|
+
x: 3.5,
|
|
73
|
+
y: 1.5,
|
|
74
|
+
_facingDirection: "x+",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
directConnections: [
|
|
80
|
+
{
|
|
81
|
+
netId: "VBUS_LED",
|
|
82
|
+
pinIds: ["R1.2", "D1.1"],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
netConnections: [
|
|
86
|
+
{
|
|
87
|
+
netId: "VBUS",
|
|
88
|
+
pinIds: ["J1.VBUS1", "J1.VBUS2", "R1.1"],
|
|
89
|
+
netLabelWidth: 0.48,
|
|
90
|
+
netLabelHeight: 0.48,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
netId: "J1_GND1",
|
|
94
|
+
pinIds: ["J1.GND1", "J1.GND2", "D1.2"],
|
|
95
|
+
netLabelWidth: 0.78,
|
|
96
|
+
netLabelHeight: 0.48,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
textBoxes: [
|
|
100
|
+
{
|
|
101
|
+
chipId: "J1",
|
|
102
|
+
center: { x: -3, y: 2.3 },
|
|
103
|
+
width: 1.6,
|
|
104
|
+
height: 0.2,
|
|
105
|
+
text: "J1 TYPE-C-31-M-12",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
chipId: "R1",
|
|
109
|
+
center: { x: 0, y: 1.95 },
|
|
110
|
+
width: 0.4,
|
|
111
|
+
height: 0.2,
|
|
112
|
+
text: "R1 1kΩ",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
chipId: "D1",
|
|
116
|
+
center: { x: 3, y: 2.15 },
|
|
117
|
+
width: 0.5,
|
|
118
|
+
height: 0.2,
|
|
119
|
+
text: "D1 white",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
availableNetLabelOrientations: {
|
|
123
|
+
VBUS: ["x+", "y+"],
|
|
124
|
+
J1_GND1: ["y-", "x+"],
|
|
125
|
+
},
|
|
126
|
+
maxMspPairDistance: 2.4,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
test("routes TYPE-C-31-M-12 VBUS through an LED with shared GND labels", () => {
|
|
130
|
+
const solver = new SchematicTracePipelineSolver(inputProblem)
|
|
131
|
+
|
|
132
|
+
solver.solve()
|
|
133
|
+
|
|
134
|
+
const output = solver.netLabelNetLabelCollisionSolver!.getOutput()
|
|
135
|
+
const gndLabels = output.netLabelPlacements.filter(
|
|
136
|
+
(label) => label.netId === "J1_GND1",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
const recoveredGroundTrace =
|
|
140
|
+
solver.longDistancePairSolver!.solvedLongDistanceTraces.find(
|
|
141
|
+
(trace) =>
|
|
142
|
+
trace.pinIds.includes("D1.2") &&
|
|
143
|
+
trace.pinIds.some((pinId) => pinId.startsWith("J1.GND")),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
expect(recoveredGroundTrace).toBeDefined()
|
|
147
|
+
expect(gndLabels).toHaveLength(1)
|
|
148
|
+
expect(solver).toMatchSolverSnapshot(import.meta.path)
|
|
149
|
+
})
|
|
@@ -4,7 +4,9 @@ import type { InputProblem } from "lib/types/InputProblem"
|
|
|
4
4
|
import "tests/fixtures/matcher"
|
|
5
5
|
import inputProblemJson from "./assets/repro-usb-power-vbus-label-detour.input.json"
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const VBUS_PIN_IDS = new Set(["schematic_port_224", "schematic_port_226"])
|
|
8
|
+
|
|
9
|
+
test("routes the usb power vbus connection without a label detour", () => {
|
|
8
10
|
const inputProblem: InputProblem = JSON.parse(
|
|
9
11
|
JSON.stringify(inputProblemJson),
|
|
10
12
|
)
|
|
@@ -12,5 +14,22 @@ test("reproduces the usb power vbus label detour", () => {
|
|
|
12
14
|
|
|
13
15
|
solver.solve()
|
|
14
16
|
|
|
17
|
+
const vbusTrace = solver.sameNetJunctionAlignmentSolver!.outputTraces.find(
|
|
18
|
+
(trace) =>
|
|
19
|
+
trace.pins.length === VBUS_PIN_IDS.size &&
|
|
20
|
+
trace.pins.every((pin) => VBUS_PIN_IDS.has(pin.pinId)),
|
|
21
|
+
)
|
|
22
|
+
const gndLabel =
|
|
23
|
+
solver.availableNetOrientationSolver!.outputNetLabelPlacements.find(
|
|
24
|
+
(label) => label.pinIds.includes("schematic_port_225"),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
expect(gndLabel?.orientation).toBe("y-")
|
|
28
|
+
expect(vbusTrace?.tracePath).toEqual([
|
|
29
|
+
{ x: 13, y: -6.2 },
|
|
30
|
+
{ x: 12.8, y: -6.2 },
|
|
31
|
+
{ x: 12.8, y: -5.8 },
|
|
32
|
+
{ x: 13, y: -5.8 },
|
|
33
|
+
])
|
|
15
34
|
expect(solver).toMatchSolverSnapshot(import.meta.path)
|
|
16
35
|
})
|