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
12 changes: 8 additions & 4 deletions src/fn/pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import { length } from "circuit-json"
import { mm } from "@tscircuit/mm"
import { base_def } from "../helpers/zod/base_def"

// Default to a 1mm square pad (the same fallback smtpad uses) so a bare `pad`
// name renders instead of throwing a raw TypeError from mm(undefined). Pass w
// and h to size the pad for a specific part.
export const pad_def = base_def.extend({
w: length,
h: length,
w: length.default("1mm").describe("width of the pad"),
h: length.default("1mm").describe("height of the pad"),
})

export type PadDef = z.input<typeof pad_def>

export const pad = (
params: PadDef,
): { circuitJson: AnySoupElement[]; parameters: PadDef } => {
rawParams: PadDef,
): { circuitJson: AnySoupElement[]; parameters: any } => {
const params = pad_def.parse(rawParams)
const { w, h } = params
const width = mm(w)
const height = mm(h)
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/pad_bare.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/pad_bare.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("pad renders from a bare name", () => {
// `pad` is advertised by getFootprintNames(); a bare `pad` used to throw a raw
// TypeError from mm(undefined) for the missing w and h. It now defaults to a
// 1mm square pad, the same fallback smtpad uses, so the name renders.
const soup = fp.string("pad").circuitJson()
const pads = soup.filter((e) => e.type === "pcb_smtpad")
expect(pads.length).toBe(1)
expect(pads[0]).toMatchObject({ width: 1, height: 1, x: 0, y: 0 })
const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "pad_bare")
})
Loading