Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/pcb/pcb_keepout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expectTypesMatch } from "src/utils/expect-types-match"
import { z } from "zod"
import { point, type Point } from "../common"
import { type Point, point } from "../common"
import { distance } from "../units"
import { expectTypesMatch } from "src/utils/expect-types-match"

export const pcb_keepout = z
.object({
Expand All @@ -15,6 +15,7 @@ export const pcb_keepout = z
pcb_keepout_id: z.string(),
layers: z.array(z.string()), // Specify layers where the keepout applies
description: z.string().optional(), // Optional description of the keepout
excluded_pcb_component_ids: z.array(z.string()).optional(),
})
.or(
z.object({
Expand All @@ -27,6 +28,7 @@ export const pcb_keepout = z
pcb_keepout_id: z.string(),
layers: z.array(z.string()), // Specify layers where the keepout applies
description: z.string().optional(), // Optional description of the keepout
excluded_pcb_component_ids: z.array(z.string()).optional(),
}),
)

Expand All @@ -44,6 +46,8 @@ export interface PCBKeepoutRect {
pcb_keepout_id: string
layers: string[]
description?: string
/** PCB components excluded from keepout DRC enforcement. */
excluded_pcb_component_ids?: string[]
}

export interface PCBKeepoutCircle {
Expand All @@ -56,6 +60,8 @@ export interface PCBKeepoutCircle {
pcb_keepout_id: string
layers: string[]
description?: string
/** PCB components excluded from keepout DRC enforcement. */
excluded_pcb_component_ids?: string[]
}

export type PCBKeepout = PCBKeepoutRect | PCBKeepoutCircle
Expand Down
33 changes: 33 additions & 0 deletions tests/pcb-keepout.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, test } from "bun:test"
import { any_circuit_element } from "../src/any_circuit_element"
import { type PCBKeepout, pcb_keepout } from "../src/pcb/pcb_keepout"

test.each([
{
type: "pcb_keepout" as const,
shape: "rect" as const,
pcb_keepout_id: "keepout_rect",
center: { x: 0, y: 0 },
width: 10,
height: 5,
layers: ["top"],
excluded_pcb_component_ids: ["pcb_component_ant1"],
},
{
type: "pcb_keepout" as const,
shape: "circle" as const,
pcb_keepout_id: "keepout_circle",
center: { x: 0, y: 0 },
radius: 5,
layers: ["top"],
excluded_pcb_component_ids: ["pcb_component_ant1"],
},
])("$shape keepout retains excluded PCB component IDs", (input) => {
const keepout = pcb_keepout.parse(input)
const circuitElement = any_circuit_element.parse(input) as PCBKeepout

expect(keepout.excluded_pcb_component_ids).toEqual(["pcb_component_ant1"])
expect(circuitElement.excluded_pcb_component_ids).toEqual([
"pcb_component_ant1",
])
})
Loading