@tscircuit/schematic-trace-solver 0.0.158 → 0.0.160
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.d.ts +41 -9
- package/dist/index.js +762 -110
- package/lib/solvers/InlineNetLabelSolver/InlineNetLabelSolver.ts +536 -94
- package/lib/solvers/InlineNetLabelSolver/pushAnchoredNetLabelsAwayFromInlineLabels.ts +9 -7
- package/lib/solvers/InlineNetLabelSolver/pushInlineTerminalLabelsAwayFromAnchoredLabels.ts +295 -0
- package/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts +15 -8
- package/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +5 -0
- package/lib/solvers/MspConnectionPairSolver/getGroundConnectionPolicy.ts +83 -0
- package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +7 -35
- package/lib/solvers/SameNetJunctionAlignmentSolver/SameNetJunctionAlignmentSolver.ts +6 -1
- package/lib/solvers/SameNetJunctionAlignmentSolver/placeGroundRailLabelsAtOuterEnd.ts +122 -0
- package/lib/solvers/SchematicTraceLinesSolver/getTraceConnectedPinComponents.ts +60 -0
- package/lib/types/InputProblem.ts +5 -4
- package/package.json +1 -1
- package/tests/bug-reports/bug-report-20260826T072956Z/__snapshots__/bug-report-20260826T072956Z.snap.svg +600 -783
- package/tests/bug-reports/bug-report-20260826T072956Z/bug-report-20260826T072956Z.test.ts +66 -1
- package/tests/fixtures/parallel-ground-rail.ts +53 -0
- package/tests/repros/__snapshots__/repro-mspm0l1306-capacitor-symmetry.snap.svg +34 -16
- package/tests/repros/repro-mspm0l1306-capacitor-symmetry.test.ts +40 -7
- package/tests/repros/repro-usb-power-vbus-label-detour.test.ts +14 -0
- package/tests/solvers/InlineNetLabelSolver/multi-pin-connected-components.test.ts +252 -0
- package/tests/solvers/InlineNetLabelSolver/opposite-side-placement.test.ts +71 -0
- package/tests/solvers/InlineNetLabelSolver/push-anchored-net-labels-away.test.ts +8 -2
- package/tests/solvers/InlineNetLabelSolver/push-inline-terminal-labels-away.test.ts +91 -0
- package/tests/solvers/InlineNetLabelSolver/two-pin-terminal-stubs-atomic.test.ts +7 -1
- package/tests/solvers/MspConnectionPairSolver/local-ground-branches.test.ts +105 -0
- package/tests/solvers/SameNetJunctionAlignmentSolver/ground-rail-label.test.ts +188 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { getConnectivityMapsFromInputProblem } from "lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem"
|
|
3
|
+
import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
|
|
4
|
+
import { placeGroundRailLabelsAtOuterEnd } from "lib/solvers/SameNetJunctionAlignmentSolver/placeGroundRailLabelsAtOuterEnd"
|
|
5
|
+
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
|
|
6
|
+
import { createParallelGroundRailProblem } from "tests/fixtures/parallel-ground-rail"
|
|
7
|
+
|
|
8
|
+
const createFixture = () => {
|
|
9
|
+
const inputProblem = createParallelGroundRailProblem()
|
|
10
|
+
const { netConnMap } = getConnectivityMapsFromInputProblem(inputProblem)
|
|
11
|
+
const globalConnNetId = netConnMap.getNetConnectedToId("GND")!
|
|
12
|
+
const pins = new Map(
|
|
13
|
+
inputProblem.chips.flatMap((chip) =>
|
|
14
|
+
chip.pins.map(
|
|
15
|
+
(pin) => [pin.pinId, { ...pin, chipId: chip.chipId }] as const,
|
|
16
|
+
),
|
|
17
|
+
),
|
|
18
|
+
)
|
|
19
|
+
const trace = (
|
|
20
|
+
mspPairId: string,
|
|
21
|
+
pinIds: [string, string],
|
|
22
|
+
path: number[][],
|
|
23
|
+
): SolvedTracePath => ({
|
|
24
|
+
mspPairId,
|
|
25
|
+
mspConnectionPairIds: [mspPairId],
|
|
26
|
+
globalConnNetId,
|
|
27
|
+
dcConnNetId: globalConnNetId,
|
|
28
|
+
userNetId: "GND",
|
|
29
|
+
pinIds,
|
|
30
|
+
pins: [pins.get(pinIds[0])!, pins.get(pinIds[1])!],
|
|
31
|
+
tracePath: path.map(([x, y]) => ({ x: x!, y: y! })),
|
|
32
|
+
})
|
|
33
|
+
const traces = [
|
|
34
|
+
trace(
|
|
35
|
+
"rail",
|
|
36
|
+
["B.2", "A.2"],
|
|
37
|
+
[
|
|
38
|
+
[1, 1],
|
|
39
|
+
[1, 0.6],
|
|
40
|
+
[0, 0.6],
|
|
41
|
+
[0, 1],
|
|
42
|
+
],
|
|
43
|
+
),
|
|
44
|
+
trace(
|
|
45
|
+
"feed",
|
|
46
|
+
["U.GND", "B.2"],
|
|
47
|
+
[
|
|
48
|
+
[2, 0.6],
|
|
49
|
+
[1, 0.6],
|
|
50
|
+
[1, 1],
|
|
51
|
+
],
|
|
52
|
+
),
|
|
53
|
+
]
|
|
54
|
+
const netLabelPlacements: NetLabelPlacement[] = [
|
|
55
|
+
{
|
|
56
|
+
globalConnNetId,
|
|
57
|
+
dcConnNetId: globalConnNetId,
|
|
58
|
+
netId: "GND",
|
|
59
|
+
mspConnectionPairIds: ["feed"],
|
|
60
|
+
pinIds: ["U.GND", "B.2"],
|
|
61
|
+
orientation: "y-",
|
|
62
|
+
anchorPoint: { x: 1, y: 0.6 },
|
|
63
|
+
center: { x: 1, y: 0.4 },
|
|
64
|
+
width: 0.4,
|
|
65
|
+
height: 0.4,
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
return { inputProblem, traces, netLabelPlacements }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const mirror of [1, -1]) {
|
|
72
|
+
test(`places the shared GND at the outer column, mirrored=${mirror}`, () => {
|
|
73
|
+
const fixture = createFixture()
|
|
74
|
+
for (const chip of fixture.inputProblem.chips) {
|
|
75
|
+
chip.center.x *= mirror
|
|
76
|
+
for (const pin of chip.pins) pin.x *= mirror
|
|
77
|
+
}
|
|
78
|
+
for (const trace of fixture.traces) {
|
|
79
|
+
for (const point of trace.tracePath) point.x *= mirror
|
|
80
|
+
}
|
|
81
|
+
const visited = new Set()
|
|
82
|
+
for (const pin of fixture.traces.flatMap((trace) => trace.pins)) {
|
|
83
|
+
if (visited.has(pin)) continue
|
|
84
|
+
pin.x *= mirror
|
|
85
|
+
visited.add(pin)
|
|
86
|
+
}
|
|
87
|
+
fixture.netLabelPlacements[0]!.anchorPoint.x *= mirror
|
|
88
|
+
fixture.netLabelPlacements[0]!.center.x *= mirror
|
|
89
|
+
const before = structuredClone(fixture)
|
|
90
|
+
const labels = placeGroundRailLabelsAtOuterEnd(fixture)
|
|
91
|
+
expect(labels[0]!.anchorPoint.x).toBeCloseTo(0, 6)
|
|
92
|
+
expect(labels[0]!.anchorPoint.y).toBeCloseTo(0.6, 6)
|
|
93
|
+
expect(labels[0]!.mspConnectionPairIds).toEqual(["rail"])
|
|
94
|
+
expect(labels[0]!.globalConnNetId).toBe(
|
|
95
|
+
before.netLabelPlacements[0]!.globalConnNetId,
|
|
96
|
+
)
|
|
97
|
+
expect(fixture).toEqual(before)
|
|
98
|
+
expect(
|
|
99
|
+
placeGroundRailLabelsAtOuterEnd({
|
|
100
|
+
...fixture,
|
|
101
|
+
netLabelPlacements: labels,
|
|
102
|
+
}),
|
|
103
|
+
).toEqual(labels)
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
test("label placement is independent of trace and endpoint ordering", () => {
|
|
108
|
+
const fixture = createFixture()
|
|
109
|
+
fixture.traces.reverse()
|
|
110
|
+
for (const trace of fixture.traces) {
|
|
111
|
+
trace.tracePath.reverse()
|
|
112
|
+
trace.pins.reverse()
|
|
113
|
+
trace.pinIds.reverse()
|
|
114
|
+
}
|
|
115
|
+
expect(placeGroundRailLabelsAtOuterEnd(fixture)[0]!.anchorPoint).toEqual({
|
|
116
|
+
x: 0,
|
|
117
|
+
y: 0.6,
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
for (const obstacle of [
|
|
122
|
+
"chip",
|
|
123
|
+
"text",
|
|
124
|
+
"trace",
|
|
125
|
+
"same-net-trace",
|
|
126
|
+
"label",
|
|
127
|
+
"same-net-label",
|
|
128
|
+
] as const) {
|
|
129
|
+
test(`keeps the existing anchor when the outer label would hit a ${obstacle}`, () => {
|
|
130
|
+
const fixture = createFixture()
|
|
131
|
+
const rect = { center: { x: 0, y: 0.4 }, width: 0.2, height: 0.2 }
|
|
132
|
+
if (obstacle === "chip")
|
|
133
|
+
fixture.inputProblem.chips.push({ ...rect, chipId: "obstacle", pins: [] })
|
|
134
|
+
if (obstacle === "text")
|
|
135
|
+
fixture.inputProblem.textBoxes = [{ ...rect, text: "annotation" }]
|
|
136
|
+
if (obstacle === "trace" || obstacle === "same-net-trace")
|
|
137
|
+
fixture.traces.push({
|
|
138
|
+
...fixture.traces[0]!,
|
|
139
|
+
mspPairId: "obstacle",
|
|
140
|
+
globalConnNetId:
|
|
141
|
+
obstacle === "trace" ? "foreign" : fixture.traces[0]!.globalConnNetId,
|
|
142
|
+
tracePath: [
|
|
143
|
+
{ x: -0.4, y: 0.4 },
|
|
144
|
+
{ x: 0.4, y: 0.4 },
|
|
145
|
+
],
|
|
146
|
+
})
|
|
147
|
+
if (obstacle === "label" || obstacle === "same-net-label")
|
|
148
|
+
fixture.netLabelPlacements.push({
|
|
149
|
+
...fixture.netLabelPlacements[0]!,
|
|
150
|
+
...rect,
|
|
151
|
+
globalConnNetId:
|
|
152
|
+
obstacle === "label"
|
|
153
|
+
? "foreign"
|
|
154
|
+
: fixture.netLabelPlacements[0]!.globalConnNetId,
|
|
155
|
+
mspConnectionPairIds: [],
|
|
156
|
+
pinIds: [],
|
|
157
|
+
anchorPoint: { x: 0, y: 0.5 },
|
|
158
|
+
})
|
|
159
|
+
expect(placeGroundRailLabelsAtOuterEnd(fixture)).toEqual(
|
|
160
|
+
fixture.netLabelPlacements,
|
|
161
|
+
)
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
test("does not move a port-only or unrelated island's GND label", () => {
|
|
166
|
+
const fixture = createFixture()
|
|
167
|
+
fixture.netLabelPlacements[0]!.mspConnectionPairIds = []
|
|
168
|
+
expect(placeGroundRailLabelsAtOuterEnd(fixture)).toEqual(
|
|
169
|
+
fixture.netLabelPlacements,
|
|
170
|
+
)
|
|
171
|
+
fixture.netLabelPlacements[0]!.mspConnectionPairIds = ["another-island"]
|
|
172
|
+
expect(placeGroundRailLabelsAtOuterEnd(fixture)).toEqual(
|
|
173
|
+
fixture.netLabelPlacements,
|
|
174
|
+
)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test("does not force staggered ground pins or power labels to an outer column", () => {
|
|
178
|
+
const fixture = createFixture()
|
|
179
|
+
fixture.traces[0]!.pins[0].y += 0.2
|
|
180
|
+
expect(placeGroundRailLabelsAtOuterEnd(fixture)).toEqual(
|
|
181
|
+
fixture.netLabelPlacements,
|
|
182
|
+
)
|
|
183
|
+
fixture.traces[0]!.pins[0].y -= 0.2
|
|
184
|
+
fixture.netLabelPlacements[0]!.orientation = "y+"
|
|
185
|
+
expect(placeGroundRailLabelsAtOuterEnd(fixture)).toEqual(
|
|
186
|
+
fixture.netLabelPlacements,
|
|
187
|
+
)
|
|
188
|
+
})
|