Skip to content
Closed
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import type { AnyCircuitElement } from "circuit-json"
import { checkCourtyardOverlap } from "lib/check-courtyard-overlap/checkCourtyardOverlap"

const square = (centerX: number) => [
{ x: centerX - 1.5, y: -1.5 },
{ x: centerX + 1.5, y: -1.5 },
{ x: centerX + 1.5, y: 1.5 },
{ x: centerX - 1.5, y: 1.5 },
]

const makePolygonComponent = ({
id,
layer,
x,
}: {
id: string
layer: "top" | "bottom"
x: number
}): AnyCircuitElement[] =>
[
{
type: "source_component",
source_component_id: `source_${id}`,
ftype: "simple_chip",
name: id,
},
{
type: "pcb_component",
pcb_component_id: `component_${id}`,
source_component_id: `source_${id}`,
center: { x, y: 0 },
width: 3,
height: 3,
layer,
rotation: 0,
},
{
type: "pcb_courtyard_polygon",
pcb_courtyard_polygon_id: `courtyard_${id}`,
pcb_component_id: `component_${id}`,
points: square(x),
layer,
color: layer === "bottom" ? "#00BFFF" : "#FF00FF",
},
] as AnyCircuitElement[]

test.failing(
"checks same-layer polygon courtyards while allowing opposite layers",
() => {
const circuitJson: AnyCircuitElement[] = [
{
type: "pcb_board",
pcb_board_id: "board",
center: { x: 0, y: 0 },
width: 14,
height: 8,
thickness: 1.6,
num_layers: 2,
material: "fr4",
},
...makePolygonComponent({ id: "top_a", layer: "top", x: -1 }),
...makePolygonComponent({ id: "top_b", layer: "top", x: 1 }),
...makePolygonComponent({ id: "bottom", layer: "bottom", x: -1.2 }),
{
type: "pcb_note_text",
pcb_note_text_id: "note_top",
text: "Top polygons overlap: expected error",
font: "tscircuit2024",
font_size: 0.45,
anchor_position: { x: 0, y: 2.8 },
anchor_alignment: "center",
layer: "top",
color: "#FF00FF",
},
{
type: "pcb_note_text",
pcb_note_text_id: "note_bottom",
text: "Bottom polygon (cyan): overlap allowed",
font: "tscircuit2024",
font_size: 0.45,
anchor_position: { x: 0, y: -2.8 },
anchor_alignment: "center",
layer: "top",
color: "#00BFFF",
},
]

const errors = checkCourtyardOverlap(circuitJson)

expect(
convertCircuitJsonToPcbSvg([...circuitJson, ...errors], {
shouldDrawErrors: true,
showCourtyards: true,
}),
).toMatchSvgSnapshot(import.meta.path)

expect(errors).toHaveLength(1)
expect(errors[0].pcb_component_ids).toEqual([
"component_top_a",
"component_top_b",
])
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { Circuit } from "tscircuit"
import { checkPcbComponentOverlap } from "lib/check-pcb-components-overlap/checkPcbComponentOverlap"

test.failing(
"checks every hole in an opposite-layer component against top courtyards",
async () => {
const circuit = new Circuit({
platform: { placementDrcChecksDisabled: true },
})
circuit.add(
<board width="14mm" height="8mm" routingDisabled>
<chip
name="J1"
layer="bottom"
footprint={
<footprint>
<hole pcbX="-3mm" pcbY="0mm" diameter="1.2mm" />
<hole pcbX="3mm" pcbY="0mm" diameter="1.2mm" />
</footprint>
}
/>
<chip
name="U1"
layer="top"
pcbX="-3mm"
footprint={
<footprint>
<courtyardrect width="2mm" height="2mm" />
</footprint>
}
/>
<pcbnotetext
text="Expected error: left hole crosses top courtyard"
pcbX={0}
pcbY="2.5mm"
fontSize="0.45mm"
color="#FF00FF"
/>
<pcbnotetext
text="Bottom J1 footprint: two drilled holes"
pcbX={0}
pcbY="-2.5mm"
fontSize="0.45mm"
color="#00E9FF"
/>
</board>,
)

await circuit.renderUntilSettled()
const circuitJson = circuit.getCircuitJson()
const errors = checkPcbComponentOverlap(circuitJson)

expect(
convertCircuitJsonToPcbSvg([...circuitJson, ...errors], {
shouldDrawErrors: true,
showCourtyards: true,
}),
).toMatchSvgSnapshot(import.meta.path)

expect(errors).toContainEqual(
expect.objectContaining({
type: "pcb_footprint_overlap_error",
pcb_hole_ids: ["pcb_hole_1"],
}),
)
},
)
Loading