diff --git a/tests/lib/check-pcb-component-overlap/__snapshots__/courtyard-polygon-layer-repro.snap.svg b/tests/lib/check-pcb-component-overlap/__snapshots__/courtyard-polygon-layer-repro.snap.svg new file mode 100644 index 0000000..ece5527 --- /dev/null +++ b/tests/lib/check-pcb-component-overlap/__snapshots__/courtyard-polygon-layer-repro.snap.svg @@ -0,0 +1 @@ +Top polygons overlap: expected errorBottom polygon (cyan): overlap allowed \ No newline at end of file diff --git a/tests/lib/check-pcb-component-overlap/__snapshots__/multiple-hole-opposite-layer-repro.snap.svg b/tests/lib/check-pcb-component-overlap/__snapshots__/multiple-hole-opposite-layer-repro.snap.svg new file mode 100644 index 0000000..dd8c235 --- /dev/null +++ b/tests/lib/check-pcb-component-overlap/__snapshots__/multiple-hole-opposite-layer-repro.snap.svg @@ -0,0 +1 @@ +Expected error: left hole crosses top courtyardBottom J1 footprint: two drilled holes \ No newline at end of file diff --git a/tests/lib/check-pcb-component-overlap/courtyard-polygon-layer-repro.test.ts b/tests/lib/check-pcb-component-overlap/courtyard-polygon-layer-repro.test.ts new file mode 100644 index 0000000..01c45e0 --- /dev/null +++ b/tests/lib/check-pcb-component-overlap/courtyard-polygon-layer-repro.test.ts @@ -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", + ]) + }, +) diff --git a/tests/lib/check-pcb-component-overlap/multiple-hole-opposite-layer-repro.test.tsx b/tests/lib/check-pcb-component-overlap/multiple-hole-opposite-layer-repro.test.tsx new file mode 100644 index 0000000..ddb35fb --- /dev/null +++ b/tests/lib/check-pcb-component-overlap/multiple-hole-opposite-layer-repro.test.tsx @@ -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( + + + + + + } + /> + + + + } + /> + + + , + ) + + 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"], + }), + ) + }, +)