Skip to content

Commit c449d7e

Browse files
authored
Add courtyard circle support (#32)
1 parent 7f6b063 commit c449d7e

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

lib/generate-footprint-tsx.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const generateFootprintTsx = (
1919
const noteDimensions = su(circuitJson).pcb_note_dimension.list()
2020
const courtyardOutlines = su(circuitJson).pcb_courtyard_outline.list()
2121
const courtyardRects = su(circuitJson).pcb_courtyard_rect.list()
22+
const courtyardCircles = su(circuitJson).pcb_courtyard_circle.list()
2223

2324
const elementStrings: string[] = []
2425

@@ -267,6 +268,19 @@ export const generateFootprintTsx = (
267268
elementStrings.push(`<courtyardrect ${attrs.join(" ")} />`)
268269
}
269270

271+
for (const courtyardCircle of courtyardCircles) {
272+
const attrs = [
273+
`pcbX={${courtyardCircle.center?.x ?? 0}}`,
274+
`pcbY={${courtyardCircle.center?.y ?? 0}}`,
275+
`radius={${courtyardCircle.radius ?? 0}}`,
276+
]
277+
if (courtyardCircle.layer !== undefined) {
278+
attrs.push(`layer="${courtyardCircle.layer}"`)
279+
}
280+
281+
elementStrings.push(`<courtyardcircle ${attrs.join(" ")} />`)
282+
}
283+
270284
if (elementStrings.length === 0) {
271285
return null
272286
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@types/react": "18",
2222
"@types/react-dom": "18",
2323
"bun-match-svg": "^0.0.15",
24-
"circuit-json": "^0.0.391",
24+
"circuit-json": "^0.0.423",
2525
"circuit-to-svg": "^0.0.333",
2626
"commander": "^13.1.0",
2727
"tscircuit": "^0.0.1444",

tests/test8-support-courtyard.test.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ test("test8 support courtyard elements", async () => {
1616
<courtyardoutline outline={[{"x":-1.8,"y":-1.4},{"x":1.8,"y":-1.4},{"x":1.8,"y":1.4},{"x":-1.8,"y":1.4}]} layer="top" />
1717
<courtyardrect pcbX={0} pcbY={0} width={4} height={3} layer="top" />
1818
<courtyardrect pcbX={0.2} pcbY={0.2} width={4.6} height={3.6} layer="bottom" />
19+
<courtyardcircle pcbX={0.4} pcbY={-0.3} radius={2.1} layer="top" />
1920
</footprint>}
2021
{...props}
2122
/>
@@ -39,16 +40,23 @@ circuit.add(
3940
`)) as any[]
4041

4142
const courtyardElements = renderedCircuitJson.filter((elm) =>
42-
["pcb_courtyard_outline", "pcb_courtyard_rect"].includes(elm.type),
43+
[
44+
"pcb_courtyard_outline",
45+
"pcb_courtyard_rect",
46+
"pcb_courtyard_circle",
47+
].includes(elm.type),
4348
)
4449

45-
expect(courtyardElements).toHaveLength(6)
50+
expect(courtyardElements).toHaveLength(8)
4651
expect(
4752
courtyardElements.filter((elm) => elm.type === "pcb_courtyard_outline"),
4853
).toHaveLength(2)
4954
expect(
5055
courtyardElements.filter((elm) => elm.type === "pcb_courtyard_rect"),
5156
).toHaveLength(4)
57+
expect(
58+
courtyardElements.filter((elm) => elm.type === "pcb_courtyard_circle"),
59+
).toHaveLength(2)
5260
})
5361

5462
const circuitJson: any = [
@@ -126,4 +134,12 @@ const circuitJson: any = [
126134
height: 3.6,
127135
layer: "bottom",
128136
},
137+
{
138+
type: "pcb_courtyard_circle",
139+
pcb_courtyard_circle_id: "pcb_courtyard_circle_0",
140+
pcb_component_id: "pcb_generic_component_0",
141+
center: { x: 0.4, y: -0.3 },
142+
radius: 2.1,
143+
layer: "top",
144+
},
129145
]

0 commit comments

Comments
 (0)