Skip to content

fix: throw clear error for zero/negative pitch in quad footprints - #873

Open
Yingtm wants to merge 2 commits into
tscircuit:mainfrom
Yingtm:fix/zero-pitch-nan
Open

Yingtm wants to merge 2 commits into
tscircuit:mainfrom
Yingtm:fix/zero-pitch-nan

Conversation

@Yingtm

@Yingtm Yingtm commented Sep 8, 2026

Copy link
Copy Markdown

Summary

Fixes #871

Passing an explicit zero pitch (e.g. lcc_p0mm, qfn16_p0mm) to quad-family footprints silently produced NaN pad x/y coordinates, which JSON.stringify serialized as null — silently corrupting the circuit-json output.

Root Cause

In src/fn/quad.ts, quadTransform uses falsy checks like if (!v.p) to decide whether a value was explicitly provided. When p = 0 (a valid number but falsy), these checks incorrectly treat it as "not set," skipping:

  • width/height derivation (v.w, v.h stay undefined)
  • pad width/length derivation (v.pw, v.pl stay undefined)

This leaves getQuadCoords computing x: -w / 2 - pcdfe + 0.1 with w = undefined, producing NaN.

Fix

Added validation at the top of quadTransform that checks whether p, px, and py are positive numbers. If any is zero or negative, a clear error is thrown:

Error: Invalid pitch (p=0): pitch must be a positive number. Use a non-zero value like p0.5mm.

This prevents silent NaN propagation and gives the user actionable feedback.

Testing

  • Added tests/quad-zero-pitch.test.ts with 4 test cases covering the fix
  • All 568 existing tests still pass (0 failures)
  • Reproduced the original bug before the fix, confirmed the error is thrown after
bun test tests/quad-zero-pitch.test.ts
# 4 pass, 0 fail

bun test
# 568 pass, 0 fail

Previously, passing a zero pitch (e.g. lcc_p0mm) silently produced
NaN pad coordinates because the falsy checks (if (!v.p)) treated 0
as 'not set', skipping width/height derivation and leaving w/h/pw/pl
undefined. This resulted in NaN being serialized as null in circuit-json.

Now quadTransform validates that p, px, and py are positive numbers
and throws a descriptive error if they are zero or negative.

Fixes tscircuit#871
@Yingtm
Yingtm force-pushed the fix/zero-pitch-nan branch from 4f81cbd to 6ac0c7f Compare September 8, 2026 15:19
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.

bug: zero pitch on quad-family footprints produces NaN pad coordinates

1 participant