Skip to content

Commit 0c0f012

Browse files
Add same-net trace alignment tests
1 parent 9f8dfd8 commit 0c0f012

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { expect, test } from "bun:test"
2+
import { SameNetTraceAlignmentSolver } from "lib/solvers/SameNetTraceAlignmentSolver/SameNetTraceAlignmentSolver"
3+
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
4+
5+
const makeTrace = (
6+
mspPairId: string,
7+
globalConnNetId: string,
8+
tracePath: Array<{ x: number; y: number }>,
9+
): SolvedTracePath =>
10+
({
11+
mspPairId,
12+
dcConnNetId: globalConnNetId,
13+
globalConnNetId,
14+
pins: [
15+
{ pinId: `${mspPairId}.1`, chipId: "U1", x: 0, y: 0 },
16+
{ pinId: `${mspPairId}.2`, chipId: "U2", x: 0, y: 0 },
17+
],
18+
tracePath,
19+
mspConnectionPairIds: [mspPairId],
20+
pinIds: [`${mspPairId}.1`, `${mspPairId}.2`],
21+
}) as SolvedTracePath
22+
23+
test("aligns close same-net horizontal interior segments", () => {
24+
const solver = new SameNetTraceAlignmentSolver({
25+
alignmentTolerance: 0.2,
26+
traces: [
27+
makeTrace("a", "GND", [
28+
{ x: 0, y: 0 },
29+
{ x: 0, y: 1 },
30+
{ x: 4, y: 1 },
31+
{ x: 4, y: 0 },
32+
]),
33+
makeTrace("b", "GND", [
34+
{ x: 1, y: 0 },
35+
{ x: 1, y: 1.12 },
36+
{ x: 3, y: 1.12 },
37+
{ x: 3, y: 0 },
38+
]),
39+
],
40+
})
41+
42+
solver.solve()
43+
44+
const [, alignedTrace] = solver.getOutput().traces
45+
expect(alignedTrace!.tracePath).toEqual([
46+
{ x: 1, y: 0 },
47+
{ x: 1, y: 1 },
48+
{ x: 3, y: 1 },
49+
{ x: 3, y: 0 },
50+
])
51+
})
52+
53+
test("does not align close segments from different nets", () => {
54+
const solver = new SameNetTraceAlignmentSolver({
55+
alignmentTolerance: 0.2,
56+
traces: [
57+
makeTrace("a", "GND", [
58+
{ x: 0, y: 0 },
59+
{ x: 0, y: 1 },
60+
{ x: 4, y: 1 },
61+
{ x: 4, y: 0 },
62+
]),
63+
makeTrace("b", "VCC", [
64+
{ x: 1, y: 0 },
65+
{ x: 1, y: 1.12 },
66+
{ x: 3, y: 1.12 },
67+
{ x: 3, y: 0 },
68+
]),
69+
],
70+
})
71+
72+
solver.solve()
73+
74+
const [, untouchedTrace] = solver.getOutput().traces
75+
expect(untouchedTrace!.tracePath[1]!.y).toBe(1.12)
76+
expect(untouchedTrace!.tracePath[2]!.y).toBe(1.12)
77+
})
78+
79+
test("aligns close same-net vertical interior segments", () => {
80+
const solver = new SameNetTraceAlignmentSolver({
81+
alignmentTolerance: 0.2,
82+
traces: [
83+
makeTrace("a", "SDA", [
84+
{ x: 0, y: 0 },
85+
{ x: 1, y: 0 },
86+
{ x: 1, y: 4 },
87+
{ x: 0, y: 4 },
88+
]),
89+
makeTrace("b", "SDA", [
90+
{ x: 0, y: 1 },
91+
{ x: 1.12, y: 1 },
92+
{ x: 1.12, y: 3 },
93+
{ x: 0, y: 3 },
94+
]),
95+
],
96+
})
97+
98+
solver.solve()
99+
100+
const [, alignedTrace] = solver.getOutput().traces
101+
expect(alignedTrace!.tracePath).toEqual([
102+
{ x: 0, y: 1 },
103+
{ x: 1, y: 1 },
104+
{ x: 1, y: 3 },
105+
{ x: 0, y: 3 },
106+
])
107+
})
108+
109+
test("does not align when the moved tail would overlap a different net", () => {
110+
const solver = new SameNetTraceAlignmentSolver({
111+
alignmentTolerance: 0.2,
112+
traces: [
113+
makeTrace("gnd-a", "GND", [
114+
{ x: 0, y: 0 },
115+
{ x: 0, y: 1 },
116+
{ x: 3, y: 1 },
117+
{ x: 3, y: 0 },
118+
]),
119+
makeTrace("gnd-b", "GND", [
120+
{ x: 2, y: 0 },
121+
{ x: 2, y: 1.1 },
122+
{ x: 4, y: 1.1 },
123+
{ x: 4, y: 0 },
124+
]),
125+
makeTrace("vcc", "VCC", [
126+
{ x: 3.2, y: 0 },
127+
{ x: 3.2, y: 1 },
128+
{ x: 3.8, y: 1 },
129+
{ x: 3.8, y: 0 },
130+
]),
131+
],
132+
})
133+
134+
solver.solve()
135+
136+
const [, gndTrace] = solver.getOutput().traces
137+
expect(gndTrace!.tracePath[1]!.y).toBe(1.1)
138+
expect(gndTrace!.tracePath[2]!.y).toBe(1.1)
139+
})

0 commit comments

Comments
 (0)