@tscircuit/schematic-trace-solver 0.0.145 → 0.0.146
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 +2 -0
- package/dist/index.js +386 -12
- package/lib/solvers/InlineNetLabelSolver/InlineNetLabelSolver.ts +30 -8
- package/lib/solvers/InlineNetLabelSolver/pushAnchoredNetLabelsAwayFromInlineLabels.ts +530 -0
- package/package.json +1 -1
- package/tests/assets/inline-net-label-anchored-label-clearance.json +56 -0
- package/tests/solvers/InlineNetLabelSolver/__snapshots__/inline-net-label-anchored-label-clearance.snap.svg +54 -0
- package/tests/solvers/InlineNetLabelSolver/inline-net-label-anchored-label-clearance.test.ts +28 -0
- package/tests/solvers/InlineNetLabelSolver/push-anchored-net-labels-away.test.ts +227 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
|
|
3
|
+
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
|
|
4
|
+
import type { InputProblem } from "lib/types/InputProblem"
|
|
5
|
+
import { pushAnchoredNetLabelsAwayFromInlineLabels } from "lib/solvers/InlineNetLabelSolver/pushAnchoredNetLabelsAwayFromInlineLabels"
|
|
6
|
+
import type { InlineNetLabelPlacement } from "lib/solvers/InlineNetLabelSolver/InlineNetLabelSolver"
|
|
7
|
+
|
|
8
|
+
test("pushes a regular endpoint label and its wick past nearby inline text", () => {
|
|
9
|
+
const inputProblem: InputProblem = {
|
|
10
|
+
chips: [
|
|
11
|
+
{
|
|
12
|
+
chipId: "U1",
|
|
13
|
+
center: { x: 0, y: 0 },
|
|
14
|
+
width: 1,
|
|
15
|
+
height: 1,
|
|
16
|
+
pins: [],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
directConnections: [],
|
|
20
|
+
netConnections: [],
|
|
21
|
+
availableNetLabelOrientations: {},
|
|
22
|
+
}
|
|
23
|
+
const netLabelPlacements: NetLabelPlacement[] = [
|
|
24
|
+
{
|
|
25
|
+
globalConnNetId: "regular-net",
|
|
26
|
+
netId: "D_PLUS",
|
|
27
|
+
mspConnectionPairIds: [],
|
|
28
|
+
pinIds: ["U1.1"],
|
|
29
|
+
orientation: "x-",
|
|
30
|
+
anchorPoint: { x: -0.7, y: 0.2 },
|
|
31
|
+
center: { x: -1.2, y: 0.2 },
|
|
32
|
+
width: 1,
|
|
33
|
+
height: 0.2,
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
const traces: SolvedTracePath[] = [
|
|
37
|
+
{
|
|
38
|
+
mspPairId: "available-net-orientation-0-D_PLUS",
|
|
39
|
+
dcConnNetId: "regular-net",
|
|
40
|
+
globalConnNetId: "regular-net",
|
|
41
|
+
pins: [] as any,
|
|
42
|
+
tracePath: [
|
|
43
|
+
{ x: -0.5, y: 0.2 },
|
|
44
|
+
{ x: -0.7, y: 0.2 },
|
|
45
|
+
],
|
|
46
|
+
mspConnectionPairIds: [],
|
|
47
|
+
pinIds: ["U1.1"],
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
const inlineNetLabelPlacements: InlineNetLabelPlacement[] = [
|
|
51
|
+
{
|
|
52
|
+
globalConnNetId: "inline-net",
|
|
53
|
+
netId: "SWCLK",
|
|
54
|
+
pinIds: ["U1.2"],
|
|
55
|
+
stubTracePath: [
|
|
56
|
+
{ x: -0.5, y: 0 },
|
|
57
|
+
{ x: -1.7, y: 0 },
|
|
58
|
+
],
|
|
59
|
+
axis: "x",
|
|
60
|
+
anchorPoint: { x: -1.1, y: 0 },
|
|
61
|
+
center: { x: -1.1, y: 0.11 },
|
|
62
|
+
width: 1.2,
|
|
63
|
+
height: 0.12,
|
|
64
|
+
side: "y+",
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
const output = pushAnchoredNetLabelsAwayFromInlineLabels({
|
|
69
|
+
inputProblem,
|
|
70
|
+
traces,
|
|
71
|
+
netLabelPlacements,
|
|
72
|
+
inlineNetLabelPlacements,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
expect(output.movedLabelCount).toBe(1)
|
|
76
|
+
expect(output.netLabelPlacements[0]!.anchorPoint.x).toBeCloseTo(-1.75)
|
|
77
|
+
expect(output.netLabelPlacements[0]!.center.x).toBeCloseTo(-2.25)
|
|
78
|
+
expect(output.traces[0]!.tracePath[0]).toEqual({ x: -0.5, y: 0.2 })
|
|
79
|
+
expect(output.traces[0]!.tracePath[1]!.x).toBeCloseTo(-1.75)
|
|
80
|
+
expect(output.traces[0]!.tracePath[1]!.y).toBeCloseTo(0.2)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test("leaves a label without a movable connector in place", () => {
|
|
84
|
+
const label: NetLabelPlacement = {
|
|
85
|
+
globalConnNetId: "regular-net",
|
|
86
|
+
netId: "D_PLUS",
|
|
87
|
+
mspConnectionPairIds: ["routed-pair"],
|
|
88
|
+
pinIds: ["U1.1", "J1.1"],
|
|
89
|
+
orientation: "x-",
|
|
90
|
+
anchorPoint: { x: -0.7, y: 0.2 },
|
|
91
|
+
center: { x: -1.2, y: 0.2 },
|
|
92
|
+
width: 1,
|
|
93
|
+
height: 0.2,
|
|
94
|
+
}
|
|
95
|
+
const inlineLabel: InlineNetLabelPlacement = {
|
|
96
|
+
globalConnNetId: "inline-net",
|
|
97
|
+
netId: "SWCLK",
|
|
98
|
+
pinIds: ["U1.2"],
|
|
99
|
+
axis: "x",
|
|
100
|
+
anchorPoint: { x: -1.1, y: 0 },
|
|
101
|
+
center: { x: -1.1, y: 0.11 },
|
|
102
|
+
width: 1.2,
|
|
103
|
+
height: 0.12,
|
|
104
|
+
side: "y+",
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const output = pushAnchoredNetLabelsAwayFromInlineLabels({
|
|
108
|
+
inputProblem: {
|
|
109
|
+
chips: [],
|
|
110
|
+
directConnections: [],
|
|
111
|
+
netConnections: [],
|
|
112
|
+
availableNetLabelOrientations: {},
|
|
113
|
+
},
|
|
114
|
+
traces: [],
|
|
115
|
+
netLabelPlacements: [label],
|
|
116
|
+
inlineNetLabelPlacements: [inlineLabel],
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
expect(output.movedLabelCount).toBe(0)
|
|
120
|
+
expect(output.netLabelPlacements[0]).toEqual(label)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test("moves a contiguous label row together and shoves an anchored obstacle", () => {
|
|
124
|
+
const inputProblem: InputProblem = {
|
|
125
|
+
chips: [
|
|
126
|
+
{
|
|
127
|
+
chipId: "U1",
|
|
128
|
+
center: { x: 0, y: 0.2 },
|
|
129
|
+
width: 1.4,
|
|
130
|
+
height: 1,
|
|
131
|
+
pins: [
|
|
132
|
+
{ pinId: "U1.minus", x: -0.7, y: 0.4, _facingDirection: "x-" },
|
|
133
|
+
{ pinId: "U1.plus", x: -0.7, y: 0.2, _facingDirection: "x-" },
|
|
134
|
+
{ pinId: "U1.inline", x: -0.7, y: 0, _facingDirection: "x-" },
|
|
135
|
+
{ pinId: "U1.gnd1", x: -0.7, y: 0.5, _facingDirection: "x-" },
|
|
136
|
+
{ pinId: "U1.gnd2", x: -2.5, y: 0.5, _facingDirection: "x+" },
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
directConnections: [],
|
|
141
|
+
netConnections: [],
|
|
142
|
+
availableNetLabelOrientations: {},
|
|
143
|
+
}
|
|
144
|
+
const netLabelPlacements: NetLabelPlacement[] = [
|
|
145
|
+
{
|
|
146
|
+
globalConnNetId: "minus-net",
|
|
147
|
+
netId: "D_MINUS",
|
|
148
|
+
mspConnectionPairIds: [],
|
|
149
|
+
pinIds: ["U1.minus"],
|
|
150
|
+
orientation: "x-",
|
|
151
|
+
anchorPoint: { x: -0.7, y: 0.4 },
|
|
152
|
+
center: { x: -1.2, y: 0.4 },
|
|
153
|
+
width: 1,
|
|
154
|
+
height: 0.2,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
globalConnNetId: "plus-net",
|
|
158
|
+
netId: "D_PLUS",
|
|
159
|
+
mspConnectionPairIds: [],
|
|
160
|
+
pinIds: ["U1.plus"],
|
|
161
|
+
orientation: "x-",
|
|
162
|
+
anchorPoint: { x: -0.7, y: 0.2 },
|
|
163
|
+
center: { x: -1.2, y: 0.2 },
|
|
164
|
+
width: 1,
|
|
165
|
+
height: 0.2,
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
globalConnNetId: "gnd-net",
|
|
169
|
+
netId: "GND",
|
|
170
|
+
mspConnectionPairIds: ["gnd-route"],
|
|
171
|
+
pinIds: ["U1.gnd1", "U1.gnd2"],
|
|
172
|
+
orientation: "y-",
|
|
173
|
+
anchorPoint: { x: -2.5, y: 0.5 },
|
|
174
|
+
center: { x: -2.5, y: 0.3 },
|
|
175
|
+
width: 0.4,
|
|
176
|
+
height: 0.4,
|
|
177
|
+
},
|
|
178
|
+
]
|
|
179
|
+
const traces: SolvedTracePath[] = [
|
|
180
|
+
{
|
|
181
|
+
mspPairId: "gnd-route",
|
|
182
|
+
dcConnNetId: "gnd-net",
|
|
183
|
+
globalConnNetId: "gnd-net",
|
|
184
|
+
pins: [] as any,
|
|
185
|
+
tracePath: [
|
|
186
|
+
{ x: -0.7, y: 0.5 },
|
|
187
|
+
{ x: -2.5, y: 0.5 },
|
|
188
|
+
],
|
|
189
|
+
mspConnectionPairIds: ["gnd-route"],
|
|
190
|
+
pinIds: ["U1.gnd1", "U1.gnd2"],
|
|
191
|
+
},
|
|
192
|
+
]
|
|
193
|
+
const inlineNetLabelPlacements: InlineNetLabelPlacement[] = [
|
|
194
|
+
{
|
|
195
|
+
globalConnNetId: "inline-net",
|
|
196
|
+
netId: "SWCLK",
|
|
197
|
+
pinIds: ["U1.inline"],
|
|
198
|
+
stubTracePath: [
|
|
199
|
+
{ x: -0.7, y: 0 },
|
|
200
|
+
{ x: -1.9, y: 0 },
|
|
201
|
+
],
|
|
202
|
+
axis: "x",
|
|
203
|
+
anchorPoint: { x: -1.3, y: 0 },
|
|
204
|
+
center: { x: -1.1, y: 0.11 },
|
|
205
|
+
width: 1.2,
|
|
206
|
+
height: 0.12,
|
|
207
|
+
side: "y+",
|
|
208
|
+
},
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
const output = pushAnchoredNetLabelsAwayFromInlineLabels({
|
|
212
|
+
inputProblem,
|
|
213
|
+
traces,
|
|
214
|
+
netLabelPlacements,
|
|
215
|
+
inlineNetLabelPlacements,
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
expect(output.movedLabelCount).toBe(3)
|
|
219
|
+
expect(output.netLabelPlacements[0]!.anchorPoint.x).toBeCloseTo(-1.75)
|
|
220
|
+
expect(output.netLabelPlacements[1]!.anchorPoint.x).toBeCloseTo(-1.75)
|
|
221
|
+
expect(output.netLabelPlacements[2]!.center.x).toBeLessThan(-2.5)
|
|
222
|
+
expect(
|
|
223
|
+
output.traces.filter((trace) =>
|
|
224
|
+
trace.mspPairId.startsWith("inline-net-label-clearance-"),
|
|
225
|
+
),
|
|
226
|
+
).toHaveLength(3)
|
|
227
|
+
})
|