Skip to content

Commit

Permalink
Feat: Introduce pad for a simple single-pin pad (#115)
Browse files Browse the repository at this point in the history
* feat: introduce pad for simple single-pin pad (#114)

* feat: fix pad.test

* feat: add single-pin pad footprint- Add pad footprint with configurable width and height- Add snapshot tests verifying dimensions- Position reference text above pad- Integrate with footprinter system

* format

* fix: slop test

* chore: output come in snapshot folder

* Chore: Use toMatchInlineSnapshot

* Fix: TypeScript not recognizing the

* Reverted .github/workflows/bun-formatcheck.yml to its original state

* Remove redudant version specification
  • Loading branch information
Ayushjhawar8 authored Feb 2, 2025
1 parent 555fe10 commit 77c16ca
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@biomejs/biome": "^1.9.4",
"@tscircuit/log-soup": "^1.0.2",
"@tscircuit/soup-util": "^0.0.11",
"@types/bun": "^1.1.10",
"@types/bun": "^1.2.2",
"@types/node": "^20.12.13",
"bun-match-svg": "^0.0.6",
"circuit-to-svg": "^0.0.42",
Expand Down
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export { stampreceiver } from "./stampreceiver"
export { lqfp } from "./lqfp"
export { sot235 } from "./sot235"
export { breakoutheaders } from "./breakoutheaders"
export { pad } from "./pad"
26 changes: 26 additions & 0 deletions src/fn/pad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { z } from "zod"
import { rectpad } from "../helpers/rectpad"
import { silkscreenRef } from "../helpers/silkscreenRef"
import type { AnySoupElement } from "circuit-json"
import { length } from "circuit-json"
import { mm } from "@tscircuit/mm"

export const pad_def = z.object({
w: length,
h: length,
})

export type PadDef = z.input<typeof pad_def>

export const pad = (params: PadDef): { circuitJson: AnySoupElement[] } => {
const { w, h } = params
const width = mm(w)
const height = mm(h)

return {
circuitJson: [
rectpad(1, 0, 0, width, height),
silkscreenRef(0, height / 2 + 0.5, 0.2),
],
}
}
10 changes: 9 additions & 1 deletion src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { isNotNull } from "./helpers/is-not-null"
import { footprintSizes } from "./helpers/passive-fn"

export type FootprinterParamsBuilder<K extends string> = {
[P in K | "params" | "soup"]: P extends "params" | "soup"
[P in K | "params" | "soup" | "circuitJson"]: P extends
| "params"
| "soup"
| "circuitJson"
? Footprinter[P]
: (v?: number | string) => FootprinterParamsBuilder<K>
}
Expand Down Expand Up @@ -85,6 +88,11 @@ export type Footprinter = {
breakoutheaders: () => FootprinterParamsBuilder<
"w" | "h" | "left" | "right" | "top" | "bottom" | "p" | "id" | "od"
>
pad: () => FootprinterParamsBuilder<"w" | "h"> & {
params: () => any
soup: () => AnySoupElement[]
circuitJson: () => AnyCircuitElement[]
}

params: () => any
/** @deprecated use circuitJson() instead */
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/zod/AnyFootprinterDefinitionOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { sot723_def } from "src/fn/sot723"
import { ssop_def } from "src/fn/ssop"
import { tssop_def } from "src/fn/tssop"
import { passive_def } from "../passive-fn"
import { pad_def } from "../../fn/pad"

export const any_footprinter_def = z.union([
axial_def,
Expand All @@ -43,6 +44,7 @@ export const any_footprinter_def = z.union([
ssop_def,
tssop_def,
passive_def,
pad_def,
])

export type AnyFootprinterDefinitionOutput = z.infer<typeof any_footprinter_def>
13 changes: 13 additions & 0 deletions tests/__snapshots__/pad.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tests/__snapshots__/pad_3x2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/fixtures/get-test-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from "node:path"
import { fp } from "../../src/footprinter"

export const getTestFixture = async (testName: string) => {
const outputDir = path.join(__dirname, "../output")
const outputDir = path.join(__dirname, "../__snapshots__")
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true })
}
Expand Down
77 changes: 77 additions & 0 deletions tests/pad.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expect, test } from "bun:test"
import { fp } from "../src/footprinter"
import { getTestFixture } from "./fixtures/get-test-fixture"

test("pad footprint", async () => {
const { snapshotSoup } = await getTestFixture("pad")
const soup = fp().pad().w(2).h(1).circuitJson()
expect(soup).toMatchInlineSnapshot(`
[
{
"height": 1,
"layer": "top",
"pcb_smtpad_id": "",
"port_hints": [
"1",
],
"shape": "rect",
"type": "pcb_smtpad",
"width": 2,
"x": 0,
"y": 0,
},
{
"anchor_alignment": "center",
"anchor_position": {
"x": 0,
"y": 1,
},
"font": "tscircuit2024",
"font_size": 0.2,
"layer": "top",
"pcb_component_id": "pcb_component_1",
"pcb_silkscreen_text_id": "silkscreen_text_1",
"text": "{REF}",
"type": "pcb_silkscreen_text",
},
]
`)
snapshotSoup(soup)
})

test("pad footprint with different dimensions", async () => {
const { snapshotSoup } = await getTestFixture("pad_3x2")
const soup = fp().pad().w(3).h(2).circuitJson()
expect(soup).toMatchInlineSnapshot(`
[
{
"height": 2,
"layer": "top",
"pcb_smtpad_id": "",
"port_hints": [
"1",
],
"shape": "rect",
"type": "pcb_smtpad",
"width": 3,
"x": 0,
"y": 0,
},
{
"anchor_alignment": "center",
"anchor_position": {
"x": 0,
"y": 1.5,
},
"font": "tscircuit2024",
"font_size": 0.2,
"layer": "top",
"pcb_component_id": "pcb_component_1",
"pcb_silkscreen_text_id": "silkscreen_text_1",
"text": "{REF}",
"type": "pcb_silkscreen_text",
},
]
`)
snapshotSoup(soup)
})
1 change: 1 addition & 0 deletions tests/slop/slop1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const SLOP_LIST = [
"bga48_grid8x8",
"bga48_p2_pad0.2",
"qfn32_p0.5mm",
"pad_w2_h1",
]

describe("Slop Tests", () => {
Expand Down

0 comments on commit 77c16ca

Please sign in to comment.