Conversation
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
force-pushed
the
fix/zero-pitch-nan
branch
from
September 8, 2026 15:19
4f81cbd to
6ac0c7f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #871
Passing an explicit zero pitch (e.g.
lcc_p0mm,qfn16_p0mm) to quad-family footprints silently producedNaNpad x/y coordinates, whichJSON.stringifyserialized asnull— silently corrupting the circuit-json output.Root Cause
In
src/fn/quad.ts,quadTransformuses falsy checks likeif (!v.p)to decide whether a value was explicitly provided. Whenp = 0(a valid number but falsy), these checks incorrectly treat it as "not set," skipping:v.w,v.hstayundefined)v.pw,v.plstayundefined)This leaves
getQuadCoordscomputingx: -w / 2 - pcdfe + 0.1withw = undefined, producingNaN.Fix
Added validation at the top of
quadTransformthat checks whetherp,px, andpyare 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
tests/quad-zero-pitch.test.tswith 4 test cases covering the fix