Skip to content

fix: handle non-numeric pin labels and (rotate N) modifier in DSN parser - #527

Open
singularitycurse26-svg wants to merge 1 commit into
tscircuit:mainfrom
singularitycurse26-svg:fix-smoothie-board-pin-labels
Open

singularitycurse26-svg wants to merge 1 commit into
tscircuit:mainfrom
singularitycurse26-svg:fix-smoothie-board-pin-labels

Conversation

@singularitycurse26-svg

Copy link
Copy Markdown

Summary

Fixes three root-cause bugs that prevented Smoothie Board DSN from converting to Circuit JSON correctly.

Root Causes

1. getPinNum(rotate N) modifier misread as pin number

Pins like (pin padstack (rotate 90) A 2000 0) had "rotate" read as the pin number instead of "A". The function now detects (rotate ...) List modifiers and skips to the next node.

2. processPin — Coordinate parsing started at wrong index

When a (rotate N) modifier was present, coordinates started at index 4, not 3. The old code read the pin label as a coordinate, causing parse failures.

3. convert-dsn-pcb-componentsNumber() coercion produced NaN

Non-numeric pin labels (A, C, +, -, GND1, etc.) were forced through Number(), producing NaN for source_port.pin_number. Now uses undefined for non-numeric labels, keeping the label in the name field.

4. convert-padstacks-to-smtpadsNumber(pin.pin_number) - 1 produced NaN

SMT pad IDs used Number(pin.pin_number) - 1 which produced NaN - 1 = NaN for non-numeric pins. Now uses pin.pin_number directly in the ID string.

Before/After

Metric Before After
NaN pin_numbers 456 0
Bad source_ports 456 0

Tests

  • tests/repros/smoothie-pin-labels.test.ts — Tests non-numeric pin labels, (rotate 90) modifier parsing, and NaN-free output on Smoothie Board repro

Closes #54

/claim #54

Three root-cause fixes for Smoothie Board DSN conversion:

1. getPinNum: Skip (rotate N) List modifier to find actual pin number
   - Pins like (pin padstack (rotate 90) A 2000 0) had 'rotate' read
   as the pin number instead of 'A'

2. processPin: Start coordinate parsing after the pin number, accounting
   for the (rotate N) modifier that shifts the pin number position
   - Without this fix, coordinates were read from the wrong index

3. convert-dsn-pcb-components: Don't force Number() on non-numeric pin
   labels (A, C, +, -, GND1, etc.) — use undefined for pin_number
   instead of NaN, keeping the label in the name field

4. convert-padstacks-to-smtpads: Use pin.pin_number directly in IDs
   instead of Number(pin.pin_number) - 1 which produced NaN-1

Before: 456 NaN pin_numbers on Smoothie Board
After: 0 NaN pin_numbers

Closes tscircuit#54

/claim tscircuit#54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

We can't convert Smoothie Board to Circuit JSON

1 participant