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
21 changes: 21 additions & 0 deletions lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { arePinsInDifferentSchematicSections } from "../../utils/arePinsInDiffer
import { isLabeledPeripheralConnection } from "../MspConnectionPairSolver/isLabeledPeripheralConnection"

const NEAREST_NEIGHBOR_COUNT = 3
const GROUND_NET_ID = "GND"

const distance = (p1: InputPin, p2: InputPin) => {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2))
Expand Down Expand Up @@ -91,6 +92,26 @@ export class LongDistancePairSolver extends BaseSolver {
const allPinIdsInNet = netConnMap.getIdsConnectedToNet(netId)
if (allPinIdsInNet.length < 2) continue

const labeledGroundConnection = inputProblem.netConnections.find(
(netConnection) =>
netConnection.netId === GROUND_NET_ID &&
netConnection.pinIds.some((pinId) => allPinIdsInNet.includes(pinId)),
)
const canPlaceGroundLabels =
(inputProblem.availableNetLabelOrientations[GROUND_NET_ID]?.length ??
0) > 0

// Long-distance ground connections are clearer as local GND labels.
// Keep short primary routes and preserve fallback routing when the
// caller has not provided a valid orientation for ground labels.
if (
labeledGroundConnection &&
labeledGroundConnection.pinIds.length > 2 &&
canPlaceGroundLabels
) {
continue
}

const unconnectedPinIds = allPinIdsInNet.filter(
(pinId) => !primaryConnectedPinIds.has(pinId),
)
Expand Down
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.
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.
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.
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.
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.
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.
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
Expand Up @@ -43,24 +43,15 @@ test("bug-report-20260806T093501Z", () => {
.traces.find(
(trace) => trace.mspPairId === "schematic_port_25-schematic_port_42",
)
expect(groundTrace?.tracePath).toEqual([
{ x: -7.7, y: 3.299999999999999 },
{ x: -7.7, y: 4.840999999999999 },
{ x: -8.699999999999998, y: 4.840999999999999 },
{ x: -8.699999999999998, y: 4.71 },
{ x: -12, y: 4.71 },
{ x: -12, y: 6.12 },
])
expect(groundTrace).toBeUndefined()

const finalOutput = solver.sameNetJunctionAlignmentSolver!.getOutput()
expect(
detectTraceLabelOverlap({
traces: finalOutput.traces,
netLabels: finalOutput.netLabelPlacements,
}).map(({ trace, label }) => `${trace.mspPairId}->${label.netId}`),
).toEqual([
"schematic_port_25-schematic_port_42->.C_CP > .pin2 to .U_GATE > .CPL",
])
).toEqual([])

expect(solver).toMatchSolverSnapshot(import.meta.path)
})
74 changes: 38 additions & 36 deletions tests/examples/__snapshots__/example14.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions tests/examples/__snapshots__/example15.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 34 additions & 30 deletions tests/examples/__snapshots__/example21.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 39 additions & 35 deletions tests/examples/__snapshots__/example25.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 66 additions & 64 deletions tests/examples/__snapshots__/example32.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 43 additions & 39 deletions tests/examples/__snapshots__/example46.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 45 additions & 41 deletions tests/examples/__snapshots__/example47.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions tests/repros/__snapshots__/repro-cc2340r5.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions tests/solvers/LongDistancePairSolver/skip-labeled-ground.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { expect, test } from "bun:test"
import { LongDistancePairSolver } from "lib/solvers/LongDistancePairSolver/LongDistancePairSolver"
import type { InputProblem } from "lib/types/InputProblem"

const createGroundProblem = ({
availableNetLabelOrientations,
}: Pick<InputProblem, "availableNetLabelOrientations">): InputProblem => ({
chips: [
{
chipId: "C1",
center: { x: -5, y: 4 },
width: 1,
height: 2,
pins: [
{
pinId: "C1.neg",
x: -5,
y: 3,
_facingDirection: "y-",
},
],
},
{
chipId: "U1",
center: { x: 0, y: 0 },
width: 3,
height: 2,
pins: [
{
pinId: "U1.GND",
x: -1.5,
y: 0.5,
_facingDirection: "x-",
},
],
},
{
chipId: "LED1",
center: { x: 3, y: -4 },
width: 1,
height: 1,
pins: [
{
pinId: "LED1.neg",
x: 3,
y: -4.5,
_facingDirection: "y-",
},
],
},
],
directConnections: [],
netConnections: [
{
netId: "GND",
pinIds: ["C1.neg", "U1.GND", "LED1.neg"],
},
],
availableNetLabelOrientations,
maxMspPairDistance: 1,
})

test("uses local labels instead of a long trace for a labeled ground net", () => {
const solver = new LongDistancePairSolver({
inputProblem: createGroundProblem({
availableNetLabelOrientations: { GND: ["y-"] },
}),
alreadySolvedTraces: [],
primaryMspConnectionPairs: [],
failedConnectionPairs: [],
})

solver.solve()

expect(solver.getOutput().newTraces).toHaveLength(0)
})

test("keeps fallback routing when ground labels cannot be placed", () => {
const solver = new LongDistancePairSolver({
inputProblem: createGroundProblem({
availableNetLabelOrientations: {},
}),
alreadySolvedTraces: [],
primaryMspConnectionPairs: [],
failedConnectionPairs: [],
})

solver.solve()

expect(solver.getOutput().newTraces.length).toBeGreaterThan(0)
})
Loading