Skip to content

Commit cb9a41b

Browse files
Update TSSOP courtyard to generic body-based stepped outline (#587)
* Update TSSOP courtyard to generic body-based stepped outline * Refactor TSSOP courtyard outline to use rect union helper
1 parent ce53900 commit cb9a41b

3 files changed

Lines changed: 42 additions & 23 deletions

File tree

src/fn/tssop.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type {
22
AnyCircuitElement,
3-
PcbCourtyardRect,
3+
PcbCourtyardOutline,
44
PcbSilkscreenPath,
55
} from "circuit-json"
66
import { length } from "circuit-json"
77
import { z } from "zod"
88
import { rectpad } from "../helpers/rectpad"
9+
import { createRectUnionOutline } from "src/helpers/rect-union-outline"
910
import { silkscreenRef, type SilkscreenRef } from "../helpers/silkscreenRef"
1011
import { base_def } from "../helpers/zod/base_def"
1112
import { u_curve } from "../helpers/u-curve"
@@ -101,24 +102,37 @@ export const tssop = (
101102
],
102103
}
103104

104-
const courtyardPadding = 0.25
105-
const silkXs = silkscreenBorder.route.map((pt) => pt.x)
106-
const silkYs = silkscreenBorder.route.map((pt) => pt.y)
107-
const padXExtent = parameters.legsoutside
108-
? parameters.w / 2 + parameters.pl
109-
: parameters.w / 2
110-
const crtMinX = Math.min(-padXExtent, ...silkXs) - courtyardPadding
111-
const crtMaxX = Math.max(padXExtent, ...silkXs) + courtyardPadding
112-
const crtMinY = Math.min(...silkYs) - courtyardPadding
113-
const crtMaxY = Math.max(...silkYs) + courtyardPadding
114-
const courtyard: PcbCourtyardRect = {
115-
type: "pcb_courtyard_rect",
116-
pcb_courtyard_rect_id: "",
105+
const roundToCourtyardGrid = (value: number) =>
106+
Math.round(value / 0.01) * 0.01
107+
const pinRowSpanY =
108+
(parameters.num_pins / 2 - 1) * parameters.p + parameters.pw
109+
const pinToeHalfSpanX =
110+
parameters.w / 2 + (parameters.legsoutside ? parameters.pl : 0)
111+
const courtyardStepInnerHalfX = roundToCourtyardGrid(parameters.w / 2 + 0.25)
112+
const courtyardStepOuterHalfX = roundToCourtyardGrid(pinToeHalfSpanX + 0.18)
113+
const courtyardStepInnerHalfY = roundToCourtyardGrid(pinRowSpanY / 2 + 0.25)
114+
const courtyardStepOuterHalfY = roundToCourtyardGrid(
115+
courtyardStepInnerHalfY + 0.35,
116+
)
117+
const courtyard: PcbCourtyardOutline = {
118+
type: "pcb_courtyard_outline",
119+
pcb_courtyard_outline_id: "",
117120
pcb_component_id: "",
118-
center: { x: (crtMinX + crtMaxX) / 2, y: (crtMinY + crtMaxY) / 2 },
119-
width: crtMaxX - crtMinX,
120-
height: crtMaxY - crtMinY,
121121
layer: "top",
122+
outline: createRectUnionOutline([
123+
{
124+
minX: -courtyardStepOuterHalfX,
125+
maxX: courtyardStepOuterHalfX,
126+
minY: -courtyardStepInnerHalfY,
127+
maxY: courtyardStepInnerHalfY,
128+
},
129+
{
130+
minX: -courtyardStepInnerHalfX,
131+
maxX: courtyardStepInnerHalfX,
132+
minY: -courtyardStepOuterHalfY,
133+
maxY: courtyardStepOuterHalfY,
134+
},
135+
]),
122136
}
123137

124138
return {
Lines changed: 1 addition & 1 deletion
Loading

tests/kicad-parity/tssop10_kicad_parity.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { compareFootprinterVsKicad } from "../fixtures/compareFootprinterVsKicad
33
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
44

55
test("parity/tssop10", async () => {
6-
const { avgRelDiff, combinedFootprintElements, booleanDifferenceSvg } =
7-
await compareFootprinterVsKicad(
8-
"tssop10_w3mm_p0.5mm",
9-
"Package_SO.pretty/TSSOP-10_3x3mm_P0.5mm.circuit.json",
10-
)
6+
const {
7+
avgRelDiff,
8+
combinedFootprintElements,
9+
booleanDifferenceSvg,
10+
courtyardDiffPercent,
11+
} = await compareFootprinterVsKicad(
12+
"tssop10_w3mm_p0.5mm",
13+
"Package_SO.pretty/TSSOP-10_3x3mm_P0.5mm.circuit.json",
14+
)
1115

16+
expect(courtyardDiffPercent).toBeLessThan(0.5)
1217
const svgContent = convertCircuitJsonToPcbSvg(combinedFootprintElements, {
1318
showCourtyards: true,
1419
})

0 commit comments

Comments
 (0)