Skip to content

fix(schema): tenthmil no longer emits "NaNmil" for missing pad coordinate/size fields - #406

Open
bnuckols13 wants to merge 1 commit into
tscircuit:mainfrom
bnuckols13:fix/tenthmil-nanmil
Open

fix(schema): tenthmil no longer emits "NaNmil" for missing pad coordinate/size fields#406
bnuckols13 wants to merge 1 commit into
tscircuit:mainfrom
bnuckols13:fix/tenthmil-nanmil

Conversation

@bnuckols13

Copy link
Copy Markdown

Problem

tenthmil (used by PadSchema, RectSchema, and TextSchema for coordinates and sizes) is .optional(), but its transform ran `${Number.parseFloat(n) * 10}mil` on every non-unit value. When a field is undefined — which happens when a short/variant EasyEDA pad string omits a trailing field such as holeRadiusNumber.parseFloat(undefined) is NaN, producing the nonsensical unit string "NaNmil".

Downstream in convert-easyeda-json-to-tscircuit-soup-json.ts, a "NaNmil" holeRadius makes mil2mm(pad.holeRadius) !== 0 true, so the pad is treated as a plated hole and emits NaN geometry — surfacing as "NaNmm" in the generated component (the exact string the convert-to-ts tests guard against with expect(result).not.toContain("NaNmm")).

Fix

Guard the parse: fall back to 0 when Number.parseFloat yields NaN, matching the safeNumber(0) convention already used in this file. A missing holeRadius now reads as 0 (an SMT pad) instead of NaN geometry.

Repro

PadSchema.parse({ type: "PAD", shape: "ELLIPSE", center: { x: 100, y: 200 },
                  width: 60, height: 60, layermask: 1, number: 1, plated: false }) // holeRadius omitted
  • before: holeRadius: "NaNmil"
  • after: holeRadius: "0mil"

Tests

Adds tests/parse-tests/pad-tenthmil-nan.test.ts (missing field → no NaN leak; valid inputs preserved). Existing suites stay green: parse-tests 15, convert-to-soup-tests 21, convert-to-ts 59.

tenthmil (used by PadSchema, RectSchema, and TextSchema for coordinates and
sizes) is optional, but its transform ran `${Number.parseFloat(n) * 10}mil` on
every non-unit value. When a field is undefined — e.g. a short EasyEDA pad
string that omits holeRadius — Number.parseFloat(undefined) is NaN, producing
the nonsensical unit string "NaNmil".

Downstream in convert-easyeda-json-to-tscircuit-soup-json.ts, a "NaNmil"
holeRadius makes mil2mm(pad.holeRadius) !== 0 true, so the pad is treated as a
plated hole and emits NaN geometry — surfacing as "NaNmm" in the generated
component, the string the convert-to-ts tests guard against.

Guard the parse: fall back to 0 when Number.parseFloat yields NaN, matching the
safeNumber(0) convention already used in this file. A missing holeRadius now
reads as 0 (an SMT pad). Adds a regression test.
@bnuckols13
bnuckols13 force-pushed the fix/tenthmil-nanmil branch from 5c7919d to 43ba552 Compare July 13, 2026 03:50
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.

1 participant