diff --git a/src/helpers/passive-fn.ts b/src/helpers/passive-fn.ts index c46e8931..26ef1201 100644 --- a/src/helpers/passive-fn.ts +++ b/src/helpers/passive-fn.ts @@ -1,4 +1,8 @@ -import type { AnyCircuitElement, PcbSilkscreenPath } from "circuit-json" +import type { + AnyCircuitElement, + PcbCourtyardRect, + PcbSilkscreenPath, +} from "circuit-json" import { rectpad } from "../helpers/rectpad" import mm from "@tscircuit/mm" import { platedhole } from "./platedhole" @@ -187,12 +191,31 @@ export const passive = (params: PassiveDef): AnyCircuitElement[] => { const textY = textbottom ? -ph / 2 - 0.9 : ph / 2 + 0.9 const silkscreenRefText: SilkscreenRef = silkscreenRef(0, textY, 0.2) + // IPC-7351B: courtyard must enclose body, pads, AND silkscreen outline + const excess = 0.25 + const silkXs = silkscreenLine.route.map((pt) => pt.x) + const silkYs = silkscreenLine.route.map((pt) => pt.y) + const crtMinX = Math.min(-(w ?? 0) / 2, -(p / 2 + pw / 2), ...silkXs) - excess + const crtMaxX = Math.max((w ?? 0) / 2, p / 2 + pw / 2, ...silkXs) + excess + const crtMinY = Math.min(-(h ?? 0) / 2, -ph / 2, ...silkYs) - excess + const crtMaxY = Math.max((h ?? 0) / 2, ph / 2, ...silkYs) + excess + const courtyard: PcbCourtyardRect = { + type: "pcb_courtyard_rect", + pcb_courtyard_rect_id: "", + pcb_component_id: "", + center: { x: (crtMinX + crtMaxX) / 2, y: (crtMinY + crtMaxY) / 2 }, + width: crtMaxX - crtMinX, + height: crtMaxY - crtMinY, + layer: "top", + } + if (tht) { return [ platedhole(1, -p / 2, 0, pw, (pw * 1) / 0.8), platedhole(2, p / 2, 0, pw, (pw * 1) / 0.8), silkscreenLine, silkscreenRefText, + courtyard, ] } return [ @@ -200,5 +223,6 @@ export const passive = (params: PassiveDef): AnyCircuitElement[] => { rectpad(["2", "right"], p / 2, 0, pw, ph), silkscreenLine, silkscreenRefText, + courtyard, ] } diff --git a/tests/kicad-parity/__snapshots__/0402_metric_parity.snap.svg b/tests/kicad-parity/__snapshots__/0402_metric_parity.snap.svg index 3dfa9d60..540d6b6e 100644 --- a/tests/kicad-parity/__snapshots__/0402_metric_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/0402_metric_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/0402_parity.snap.svg b/tests/kicad-parity/__snapshots__/0402_parity.snap.svg index 5a674199..3df6d490 100644 --- a/tests/kicad-parity/__snapshots__/0402_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/0402_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/0603_metric_parity.snap.svg b/tests/kicad-parity/__snapshots__/0603_metric_parity.snap.svg index fbd414f3..554efef4 100644 --- a/tests/kicad-parity/__snapshots__/0603_metric_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/0603_metric_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/0603_parity.snap.svg b/tests/kicad-parity/__snapshots__/0603_parity.snap.svg index 9a81e02e..fd46a0d4 100644 --- a/tests/kicad-parity/__snapshots__/0603_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/0603_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/0805_parity.snap.svg b/tests/kicad-parity/__snapshots__/0805_parity.snap.svg index 803db54d..8ec19183 100644 --- a/tests/kicad-parity/__snapshots__/0805_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/0805_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/1206_parity.snap.svg b/tests/kicad-parity/__snapshots__/1206_parity.snap.svg index a4910432..7fa1fdf5 100644 --- a/tests/kicad-parity/__snapshots__/1206_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/1206_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/1210_parity.snap.svg b/tests/kicad-parity/__snapshots__/1210_parity.snap.svg index 8840e97e..058f9d27 100644 --- a/tests/kicad-parity/__snapshots__/1210_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/1210_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/1812_parity.snap.svg b/tests/kicad-parity/__snapshots__/1812_parity.snap.svg index a8ac3582..7cbf5799 100644 --- a/tests/kicad-parity/__snapshots__/1812_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/1812_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/2010_parity.snap.svg b/tests/kicad-parity/__snapshots__/2010_parity.snap.svg index 646f7b18..b3559627 100644 --- a/tests/kicad-parity/__snapshots__/2010_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/2010_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file diff --git a/tests/kicad-parity/__snapshots__/2512_parity.snap.svg b/tests/kicad-parity/__snapshots__/2512_parity.snap.svg index d1105680..10fd0b08 100644 --- a/tests/kicad-parity/__snapshots__/2512_parity.snap.svg +++ b/tests/kicad-parity/__snapshots__/2512_parity.snap.svg @@ -1 +1 @@ -{REF}Diff: 0.00% \ No newline at end of file +{REF}Diff: 0.00% \ No newline at end of file