Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions src/fn/pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ 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<typeof pad_def>

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: [
Expand Down
20 changes: 20 additions & 0 deletions tests/pad-bare-string.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
Loading