From 5e0f4c0ff38422b98104bed27a16960927759a20 Mon Sep 17 00:00:00 2001 From: Ahmed Shebani Date: Fri, 27 Nov 2026 06:21:49 +0100 Subject: [PATCH] Recognize same-net pour contact at net trace endpoints --- .../check-traces-are-contiguous.ts | 25 ++++++++++- ...races-are-contiguous-pour-contact.snap.svg | 2 +- ...traces-are-contiguous-pour-contact.test.ts | 41 ++++++++++++++++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/lib/check-traces-are-contiguous/check-traces-are-contiguous.ts b/lib/check-traces-are-contiguous/check-traces-are-contiguous.ts index 8a681e44..196b6983 100644 --- a/lib/check-traces-are-contiguous/check-traces-are-contiguous.ts +++ b/lib/check-traces-are-contiguous/check-traces-are-contiguous.ts @@ -30,6 +30,7 @@ import { } from "circuit-json-to-connectivity-map" import { getLayersOfPcbElement } from "../util/getLayersOfPcbElement" import { endpointTouchesVia, getViaContactIndex } from "./via-contact-index" +import { getPourContactTester } from "../check-dangling-traces/pour-contact-index" import { createRouteViaContactContext, routeViaConnectsAdjacentWires, @@ -388,6 +389,24 @@ function checkTracesAreContiguous( ) return viaContactIndex } + let touchesPour: ReturnType | undefined + const endpointTouchesPour = ( + trace: PcbTrace, + point: PcbTraceRoutePoint, + width = 0, + ) => { + if (point.route_type !== "wire") return false + const connectivity = getFullConnectivityMap() + const netId = connectivity.getNetConnectedToId(trace.pcb_trace_id) + if (!netId) return false + touchesPour ??= getPourContactTester(circuitJson, connectivity) + return touchesPour({ + netId, + layers: [point.layer], + center: point, + radius: width / 2, + }) + } const checkedSourceTraceIds = new Set() for (const pad of pcbSmtPads) { @@ -658,7 +677,8 @@ function checkTracesAreContiguous( ownerTrace: trace, index: getViaIndex(), connectivity: getFullConnectivityMap(), - })) + })) || + endpointTouchesPour(trace, firstPoint, firstEndpointTraceCopperWidth) const lastIsConnected = lastConnectsToAnyPad || lastConnectsToLogicallyConnectedTraceCopper || @@ -669,7 +689,8 @@ function checkTracesAreContiguous( ownerTrace: trace, index: getViaIndex(), connectivity: getFullConnectivityMap(), - })) + })) || + endpointTouchesPour(trace, lastPoint, lastEndpointTraceCopperWidth) const endpointsAreSame = firstPoint.route_type === "wire" && lastPoint.route_type === "wire" && diff --git a/tests/lib/__snapshots__/check-traces-are-contiguous-pour-contact.snap.svg b/tests/lib/__snapshots__/check-traces-are-contiguous-pour-contact.snap.svg index 3ddc093d..c214be0f 100644 --- a/tests/lib/__snapshots__/check-traces-are-contiguous-pour-contact.snap.svg +++ b/tests/lib/__snapshots__/check-traces-are-contiguous-pour-contact.snap.svg @@ -1 +1 @@ -Trace [unnamed trace] has disconnected endpoint at (2.00, 0.00) \ No newline at end of file + \ No newline at end of file diff --git a/tests/lib/check-traces-are-contiguous-pour-contact.test.ts b/tests/lib/check-traces-are-contiguous-pour-contact.test.ts index bc44f055..2d97a6cd 100644 --- a/tests/lib/check-traces-are-contiguous-pour-contact.test.ts +++ b/tests/lib/check-traces-are-contiguous-pour-contact.test.ts @@ -72,11 +72,48 @@ const pour: PcbCopperPour = { test("net-level trace ending in a ground pour", () => { const circuit = [...board, pour] const errors = checkTracesAreContiguous(circuit) - expect(errors).toHaveLength(1) - expect(errors[0]?.center).toEqual({ x: 2, y: 0 }) + expect(errors).toEqual([]) expect( convertCircuitJsonToPcbSvg([...circuit, ...errors], { shouldDrawErrors: true, }), ).toMatchSvgSnapshot(import.meta.path) }) + +test("a pour on another layer or net leaves the endpoint disconnected", () => { + for (const otherPour of [ + { ...pour, layer: "bottom" as const }, + { ...pour, source_net_id: "source_net_vcc" }, + ]) { + const errors = checkTracesAreContiguous([...board, otherPour]) + expect(errors.map((error) => error.center)).toEqual([{ x: 2, y: 0 }]) + } +}) + +test("only the copper of a round trace end can bridge the gap to a pour", () => { + for (const [leftEdge, expectedErrors] of [ + [2.1, 0], + [2.2, 1], + ]) { + const errors = checkTracesAreContiguous([ + ...board, + { ...pour, center: { x: leftEdge + pour.width / 2, y: 0 } }, + ]) + expect(errors).toHaveLength(expectedErrors) + } +}) + +test("a flat-ended trace must reach the pour", () => { + const flatEnded = board.map((element) => + element.type === "pcb_trace" + ? { ...element, route_thickness_mode: "interpolated" as const } + : element, + ) + expect(checkTracesAreContiguous([...flatEnded, pour])).toEqual([]) + expect( + checkTracesAreContiguous([ + ...flatEnded, + { ...pour, center: { x: 4.1, y: 0 } }, + ]), + ).toHaveLength(1) +})