Skip to content

Commit 9c37cfd

Browse files
authored
add the via route_type only once in the pcb_trace segment (#117)
1 parent 666f73f commit 9c37cfd

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/dsn-pcb/dsn-json-to-circuit-json/convert-dsn-session-to-circuit-json.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ export function convertDsnSessionToCircuitJson(
142142
const fromLayer = connectingWires[0]?.layer || "top"
143143
const toLayer = connectingWires[1]?.layer || "bottom"
144144

145-
// Add via point to each trace that connects to it
146-
sessionElements.forEach((element) => {
145+
// Add via point to the first trace that connects to it (not all traces)
146+
let viaAdded = false
147+
for (const element of sessionElements) {
148+
if (viaAdded) break
147149
if (element.type === "pcb_trace") {
148150
const trace = element as PcbTrace
149151
// Check all points in the route, not just the last one
@@ -158,11 +160,12 @@ export function convertDsnSessionToCircuitJson(
158160
from_layer: fromLayer,
159161
to_layer: toLayer,
160162
})
163+
viaAdded = true
161164
break // Found the matching point, no need to continue checking
162165
}
163166
}
164167
}
165-
})
168+
}
166169

167170
sessionElements.push({
168171
...convertViaToPcbVia({

tests/repros/repro10-via.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ test("Number of vias in the pcb_trace route should match the number of pcb_via e
3636
})
3737
})
3838

39-
// Each via point is counted twice (once for each layer)
40-
routeViaPointsCount /= 2
41-
4239
const outputPcbVias = circuitJsonFromSession.filter(
4340
(element) => element.type === "pcb_via",
4441
)
4542

43+
// Each via appears once in the route and once as a pcb_via element
4644
expect(routeViaPointsCount).toBe(outputPcbVias.length)
4745
})

0 commit comments

Comments
 (0)