Skip to content

fix: deduplicate vias from freerouting session output#126

Open
blessuselessk wants to merge 2 commits intotscircuit:mainfrom
blessuselessk:fix/deduplicate-freerouting-vias
Open

fix: deduplicate vias from freerouting session output#126
blessuselessk wants to merge 2 commits intotscircuit:mainfrom
blessuselessk:fix/deduplicate-freerouting-vias

Conversation

@blessuselessk
Copy link
Copy Markdown

@blessuselessk blessuselessk commented Mar 18, 2026

Summary

  • Freerouting can output duplicate vias at the same (x, y) coordinates, both within a single net's vias array and across different nets in the session file
  • Added a Set-based deduplication keyed by "${viaX},${viaY}" in convertDsnSessionToCircuitJson that skips vias already processed at the same coordinates
  • This prevents duplicate pcb_via elements and duplicate via route points in the circuit JSON output

Test plan

  • Added repro15-duplicate-vias.test.ts with two cases:
    • Duplicate vias within the same net (3 identical coords -> 1 pcb_via)
    • Duplicate vias across different nets (shared coord -> deduplicated)
  • All 45 existing tests pass with no regressions
  • Existing repro10-via.test.ts (via count consistency) still passes

Freerouting can output duplicate vias at the same coordinates, both
within a single net and across different nets. This causes duplicate
pcb_via elements in the circuit JSON output.

Track via positions in a Set keyed by coordinates and skip duplicates
during session-to-circuit-json conversion.

Closes tscircuit/tscircuit#2408
Changed addedViaKeys from Set to Map to track which net first
claimed each via location. When a via at the same coordinates
appears in a different net, emit a console.warn about a possible
short circuit in the routing output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant