Skip to content
Open
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
26 changes: 21 additions & 5 deletions lib/check-traces-are-contiguous/check-traces-are-contiguous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function routePointConnectsToAnotherExpectedPort(
const expectedPads = padMap.get(expectedPort.pcb_port_id)
return (
expectedPads?.some((pad) =>
isPointInPad({ x: point.x, y: point.y }, pad),
isPointInPad({ x: point.x, y: point.y }, pad, point.layer),
) ?? false
)
})
Expand Down Expand Up @@ -273,13 +273,21 @@ function checkTracesAreContiguous(
const isFirstPointConnected =
firstPoint.route_type === "wire" &&
pads.some((pad) =>
isPointInPad({ x: firstPoint.x, y: firstPoint.y }, pad),
isPointInPad(
{ x: firstPoint.x, y: firstPoint.y },
pad,
firstPoint.layer,
),
)

const isLastPointConnected =
lastPoint.route_type === "wire" &&
pads.some((pad) =>
isPointInPad({ x: lastPoint.x, y: lastPoint.y }, pad),
isPointInPad(
{ x: lastPoint.x, y: lastPoint.y },
pad,
lastPoint.layer,
),
)

if (!isFirstPointConnected && !isLastPointConnected) {
Expand Down Expand Up @@ -326,15 +334,23 @@ function checkTracesAreContiguous(
if (
firstPoint.route_type === "wire" &&
pads.some((pad) =>
isPointInPad({ x: firstPoint.x, y: firstPoint.y }, pad),
isPointInPad(
{ x: firstPoint.x, y: firstPoint.y },
pad,
firstPoint.layer,
),
)
) {
firstConnectsToAnyPad = true
}
if (
lastPoint.route_type === "wire" &&
pads.some((pad) =>
isPointInPad({ x: lastPoint.x, y: lastPoint.y }, pad),
isPointInPad(
{ x: lastPoint.x, y: lastPoint.y },
pad,
lastPoint.layer,
),
)
) {
lastConnectsToAnyPad = true
Expand Down
11 changes: 11 additions & 0 deletions lib/check-traces-are-contiguous/is-point-in-pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ function isPointOnSegment(
export function isPointInPad(
point: { x: number; y: number },
pad: PcbSmtPad | PcbPlatedHole,
layer?: string,
): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if we have a layer type we can import from circuit-json. Otherwise looks good

// A trace endpoint only connects to a pad on the same layer (a top-layer
// wire can't land on a bottom-layer smt pad without a via).
if (layer !== undefined) {
const padIsOnLayer =
pad.type === "pcb_smtpad"
? pad.layer === layer
: pad.layers.some((padLayer) => padLayer === layer)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify this, remove ternary

if (!padIsOnLayer) return false
}

if (pad.type === "pcb_smtpad") {
if (pad.shape === "circle") {
return getDistanceBetweenPoints(point, pad) <= pad.radius
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/lib/check-traces-are-contiguous.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ test("still reports a source-trace branch that does not reach a required port",
)
})

test.failing(
test(
"errors when a trace endpoint touches a pad on a different layer",
() => {
// A top-layer wire endpoint at (1,0) coincides with a BOTTOM-layer pad.
Expand Down Expand Up @@ -475,7 +475,7 @@ test.failing(
},
)

test.failing(
test(
"draws an error where a trace endpoint touches a pad on a different layer",
() => {
// Same scenario rendered with shouldDrawErrors: a top-layer wire ends on
Expand Down
Loading