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
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export function checkEachPcbTraceNonOverlapping(
circuitJson: AnyCircuitElement[],
{
connMap,
minSpacing = DEFAULT_TRACE_MARGIN,
}: {
connMap?: ConnectivityMap
minSpacing?: number
} = {},
): PcbTraceError[] {
const errors: PcbTraceError[] = []
Expand Down Expand Up @@ -101,7 +103,7 @@ export function checkEachPcbTraceNonOverlapping(

// For each segment, check it if overlaps with anything collidable
for (const segmentA of pcbTraceSegments) {
const requiredMargin = DEFAULT_TRACE_MARGIN
const requiredMargin = minSpacing
const bounds = getCollidableBounds(segmentA)
const nearbyObjects = spatialIndex.getObjectsInBounds(
bounds,
Expand Down Expand Up @@ -134,7 +136,7 @@ export function checkEachPcbTraceNonOverlapping(
) -
segmentA.thickness / 2 -
segmentB.thickness / 2
if (gap > DEFAULT_TRACE_MARGIN - EPSILON) continue
if (gap > minSpacing - EPSILON) continue

const pcb_trace_error_id = `overlap_${segmentA.pcb_trace_id}_${segmentB.pcb_trace_id}`
const pcb_trace_error_id_reverse = `overlap_${segmentB.pcb_trace_id}_${segmentA.pcb_trace_id}`
Expand Down Expand Up @@ -182,7 +184,7 @@ export function checkEachPcbTraceNonOverlapping(
{ x: obj.x, y: obj.y, radius },
)
const gap = distance - segmentA.thickness / 2
if (gap > DEFAULT_TRACE_MARGIN - EPSILON) continue
if (gap > minSpacing - EPSILON) continue

const pcb_trace_error_id = `overlap_${segmentA.pcb_trace_id}_${primaryObjId}`
if (errorIds.has(pcb_trace_error_id)) continue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { expect, test, describe } from "bun:test"
import { checkEachPcbTraceNonOverlapping } from "lib/check-each-pcb-trace-non-overlapping/check-each-pcb-trace-non-overlapping"
import type { AnySoupElement, PCBTrace, PCBSMTPad } from "circuit-json"
import type {
AnySoupElement,
PCBTrace,
PCBSMTPad,
AnyCircuitElement,
} from "circuit-json"

describe("checkEachPcbTraceNonOverlapping", () => {
test("should return no errors when traces don't overlap", () => {
Expand Down Expand Up @@ -138,4 +143,70 @@ describe("checkEachPcbTraceNonOverlapping", () => {
expect(errors[0].message).toContain("overlaps with")
expect(errors[0].pcb_trace_id).toBe("trace1")
})

test("should allow overriding minimum spacing", () => {
const circuitJson: AnyCircuitElement[] = [
{
type: "source_trace",
source_trace_id: "trace1",
connected_source_port_ids: ["port1", "port2"],
connected_source_net_ids: [],
},
{
type: "source_trace",
source_trace_id: "trace2",
connected_source_port_ids: ["port3", "port4"],
connected_source_net_ids: [],
},
{
type: "pcb_trace",
pcb_trace_id: "trace1",
route: [
{
route_type: "wire",
x: 0,
y: 0,
width: 0.1,
layer: "top",
start_pcb_port_id: "port1",
},
{
route_type: "wire",
x: 1,
y: 0,
width: 0.1,
layer: "top",
end_pcb_port_id: "port2",
},
],
},
{
type: "pcb_trace",
pcb_trace_id: "trace2",
route: [
{
route_type: "wire",
x: 0,
y: 0.19,
width: 0.1,
layer: "top",
start_pcb_port_id: "port3",
},
{
route_type: "wire",
x: 1,
y: 0.19,
width: 0.1,
layer: "top",
end_pcb_port_id: "port4",
},
],
},
]

expect(checkEachPcbTraceNonOverlapping(circuitJson)).toHaveLength(1)
expect(
checkEachPcbTraceNonOverlapping(circuitJson, { minSpacing: 0 }),
).toEqual([])
})
})
Loading