From 37a2ce89f4a1139e9decaff9380a5f3d2cc4ca89 Mon Sep 17 00:00:00 2001 From: Rudra Sarker Date: Sun, 16 Aug 2026 02:32:31 +0600 Subject: [PATCH 1/2] fix(pad): default pad dimensions to 1mm when omitted Fixes #788 by making w and h optional in pad_def and defaulting width/height to 1mm in pad(), matching the behavior of smtpad. --- src/fn/pad.ts | 17 ++++++++++++----- tests/pad-bare-string.test.ts | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 tests/pad-bare-string.test.ts diff --git a/src/fn/pad.ts b/src/fn/pad.ts index 4bce6f0a7..f01051776 100644 --- a/src/fn/pad.ts +++ b/src/fn/pad.ts @@ -7,8 +7,12 @@ import { mm } from "@tscircuit/mm" import { base_def } from "../helpers/zod/base_def" export const pad_def = base_def.extend({ - w: length, - h: length, + w: length.optional(), + h: length.optional(), + width: length.optional(), + height: length.optional(), + s: length.optional(), + size: length.optional(), }) export type PadDef = z.input @@ -16,9 +20,12 @@ export type PadDef = z.input export const pad = ( params: PadDef, ): { circuitJson: AnySoupElement[]; parameters: PadDef } => { - const { w, h } = params - const width = mm(w) - const height = mm(h) + const width = mm( + params.w ?? params.width ?? params.s ?? params.size ?? "1mm", + ) + const height = mm( + params.h ?? params.height ?? params.s ?? params.size ?? "1mm", + ) return { circuitJson: [ diff --git a/tests/pad-bare-string.test.ts b/tests/pad-bare-string.test.ts new file mode 100644 index 000000000..b30f66854 --- /dev/null +++ b/tests/pad-bare-string.test.ts @@ -0,0 +1,20 @@ +import { test, expect } from "bun:test" +import { fp } from "../src" + +test("pad bare string defaults to 1mm dimensions (#788)", () => { + const circuitJson = fp.string("pad").circuitJson() + + const smtpads = circuitJson.filter((e) => e.type === "pcb_smtpad") as any[] + expect(smtpads.length).toBe(1) + expect(smtpads[0].width).toBe(1) + expect(smtpads[0].height).toBe(1) +}) + +test("pad with specified dimensions parses properly", () => { + const circuitJson = fp.string("pad_w2mm_h3mm").circuitJson() + + const smtpads = circuitJson.filter((e) => e.type === "pcb_smtpad") as any[] + expect(smtpads.length).toBe(1) + expect(smtpads[0].width).toBe(2) + expect(smtpads[0].height).toBe(3) +}) From 1e631bcaf87de5680eaf94d170d42f9bafa65bdf Mon Sep 17 00:00:00 2001 From: Rudra Sarker Date: Sun, 16 Aug 2026 04:23:05 +0600 Subject: [PATCH 2/2] style: format pad definitions with biome --- src/fn/pad.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fn/pad.ts b/src/fn/pad.ts index f01051776..3081f3fdb 100644 --- a/src/fn/pad.ts +++ b/src/fn/pad.ts @@ -20,9 +20,7 @@ export type PadDef = z.input export const pad = ( params: PadDef, ): { circuitJson: AnySoupElement[]; parameters: PadDef } => { - const width = mm( - params.w ?? params.width ?? params.s ?? params.size ?? "1mm", - ) + const width = mm(params.w ?? params.width ?? params.s ?? params.size ?? "1mm") const height = mm( params.h ?? params.height ?? params.s ?? params.size ?? "1mm", )