Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/fn/quad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ export const quadTransform = <T extends z.infer<typeof base_quad_def>>(
`Conflicting lrpl (${v.lrpl}) and leftrightpadlength (${v.leftrightpadlength})`,
)
}
if (v.p !== undefined && v.p <= 0) {
throw new Error(
`Invalid pitch (p=${v.p}): pitch must be a positive number. Use a non-zero value like p0.5mm.`,
)
}
if (v.px !== undefined && v.px <= 0) {
throw new Error(
`Invalid horizontal pitch (px=${v.px}): pitch must be a positive number.`,
)
}
if (v.py !== undefined && v.py <= 0) {
throw new Error(
`Invalid vertical pitch (py=${v.py}): pitch must be a positive number.`,
)
}
v.leftrightpadwidth = v.leftrightpadwidth ?? v.lrpw
v.leftrightpadlength = v.leftrightpadlength ?? v.lrpl

Expand Down
30 changes: 30 additions & 0 deletions tests/quad-zero-pitch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test, expect } from "bun:test"
import { fp } from "../src/footprinter"

test("lcc with zero pitch throws a clear error", () => {
expect(() => fp.string("lcc_p0mm").circuitJson()).toThrow(
/pitch must be a positive number/,
)
})

test("qfn16 with zero pitch throws a clear error", () => {
expect(() => fp.string("qfn16_p0mm").circuitJson()).toThrow(
/pitch must be a positive number/,
)
})

test("quad with zero px throws a clear error", () => {
expect(() => fp.string("quad16_w4_h4_p0.5mm_px0mm").circuitJson()).toThrow(
/pitch must be a positive number/,
)
})

test("normal pitch still works", () => {
const soup = fp.string("quad16_w4_l4_p0.4_pw0.25_pl0.4").circuitJson()
const pads = soup.filter((e) => e.type === "pcb_smtpad")
expect(pads.length).toBeGreaterThan(0)
for (const pad of pads) {
expect(Number.isNaN(pad.x)).toBe(false)
expect(Number.isNaN(pad.y)).toBe(false)
}
})
Loading