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
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export class AvailableNetOrientationSolver extends BaseSolver {
(connection) => connection.netId === label.netId,
)
const isTwoPinNet = netConnection?.pinIds.length === 2
const isTwoPinLabel = label.pinIds.length === 2
const isDownwardGroundRail =
netConnection?.isGround &&
isXOrientation(label.orientation) &&
Expand Down Expand Up @@ -510,6 +511,19 @@ export class AvailableNetOrientationSolver extends BaseSolver {
if (traceAnchorCandidate) return traceAnchorCandidate
}

if (
isTwoPinLabel &&
orientations.length === 1 &&
isYOrientation(requiredOrientation)
) {
const endpointCandidate = this.findValidTwoPinEndpointCandidate(
label,
requiredOrientation,
labelIndex,
)
if (endpointCandidate) return endpointCandidate
}

if (
isTwoPinNet &&
orientations.length === 1 &&
Expand Down Expand Up @@ -701,6 +715,80 @@ export class AvailableNetOrientationSolver extends BaseSolver {
return null
}

/**
* When a two-pin label was initially attached to the first bend beside a
* component, keep a vertical replacement on that component's pin column.
* This avoids turning the old bend into a tee when the pin itself provides
* the shorter, cleaner branch source.
*/
private findValidTwoPinEndpointCandidate(
label: NetLabelPlacement,
orientation: "y+" | "y-",
labelIndex: number,
) {
const pins = label.pinIds.flatMap((pinId) => {
const pin = this.pinMap[pinId]
return pin ? [pin] : []
})
if (
pins.length !== 2 ||
pins[0]!._facingDirection !== pins[1]!._facingDirection ||
(pins[0]!._facingDirection !== "x+" && pins[0]!._facingDirection !== "x-")
) {
return null
}

const endpointPins = label.mspConnectionPairIds.flatMap((traceId) => {
const trace = this.traceMap[traceId]
if (!trace || trace.tracePath.length < 2) return []

return [
{ point: trace.tracePath[0]!, neighbor: trace.tracePath[1]! },
{
point: trace.tracePath.at(-1)!,
neighbor: trace.tracePath.at(-2)!,
},
].filter(
({ point, neighbor }) =>
Math.abs(neighbor.x - label.anchorPoint.x) <= EPS &&
Math.abs(neighbor.y - label.anchorPoint.y) <= EPS &&
(Math.abs(point.x - label.anchorPoint.x) > EPS ||
Math.abs(point.y - label.anchorPoint.y) > EPS) &&
trace.pins.some(
(pin) =>
Math.abs(pin.x - point.x) <= EPS &&
Math.abs(pin.y - point.y) <= EPS,
),
)
})

endpointPins.sort(
(first, second) =>
Math.abs(first.point.x - label.anchorPoint.x) +
Math.abs(first.point.y - label.anchorPoint.y) -
(Math.abs(second.point.x - label.anchorPoint.x) +
Math.abs(second.point.y - label.anchorPoint.y)),
)

if (endpointPins.length > 0) {
const candidate = this.findValidCandidateInShiftColumn({
label,
labelIndex,
orientation,
direction: dir(orientation),
baseAnchor: this.getWickOffsetAnchor(label.anchorPoint, orientation),
maxSearchDistance: this.maxSearchDistance,
outwardDistance: 0,
phase: "lateral-shift",
stopOnTraceCollision: false,
connectorSource: label.anchorPoint,
})
if (candidate) return candidate
}

return null
}

private hasTraceContinuingInOrientation(
label: NetLabelPlacement,
orientation: "y+" | "y-",
Expand Down
44 changes: 43 additions & 1 deletion lib/solvers/NetLabelToTraceSolver/NetLabelToTraceSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
type InlineNetLabelPlacement,
visualizeInlineNetLabelOutput,
} from "../InlineNetLabelSolver/InlineNetLabelSolver"
import { extendVerticalTracePathAtInteriorPoint } from "../AvailableNetOrientationSolver/traces"
import { reduceTraceCrossings } from "./reduceTraceCrossings"

type GlobalConnNetId = NetLabelPlacement["globalConnNetId"]
Expand All @@ -52,6 +53,47 @@ const MAX_ROUTED_COMPONENT_RECOVERY_PERPENDICULAR_OFFSET = 0.25
const getCanonicalPairKey = (firstPinId: PinId, secondPinId: PinId) =>
[firstPinId, secondPinId].sort().join("--")

const foldVerticalLabelConnectorsIntoHostTraces = (
traces: SolvedTracePath[],
) => {
const removedTraceIds = new Set<string>()
const output = traces.map((trace) => ({ ...trace }))

for (const connector of output) {
if (!connector.mspPairId.startsWith("available-net-orientation-")) continue
const [sourcePoint, extensionEndPoint] = connector.tracePath
if (
connector.tracePath.length !== 2 ||
!sourcePoint ||
!extensionEndPoint ||
Math.abs(sourcePoint.x - extensionEndPoint.x) > 1e-6
) {
continue
}

const hostTrace = output.find(
(trace) =>
trace !== connector &&
trace.globalConnNetId === connector.globalConnNetId &&
extendVerticalTracePathAtInteriorPoint({
tracePath: trace.tracePath,
sourcePoint,
extensionEndPoint,
}) !== null,
)
if (!hostTrace) continue

hostTrace.tracePath = extendVerticalTracePathAtInteriorPoint({
tracePath: hostTrace.tracePath,
sourcePoint,
extensionEndPoint,
})!
removedTraceIds.add(connector.mspPairId)
}

return output.filter((trace) => !removedTraceIds.has(trace.mspPairId))
}

const getPerpendicularOffset = (firstPoint: Point, secondPoint: Point) => {
const xDistance = Math.abs(firstPoint.x - secondPoint.x)
const yDistance = Math.abs(firstPoint.y - secondPoint.y)
Expand Down Expand Up @@ -93,7 +135,7 @@ export class NetLabelToTraceSolver extends BaseSolver {
constructor(private input: InlineNetLabelOutput) {
super()
this.inputProblem = input.inputProblem
this.outputTraces = [...input.traces]
this.outputTraces = foldVerticalLabelConnectorsIntoHostTraces(input.traces)
this.outputNetLabelPlacements = [...input.netLabelPlacements]

const { chipMap, pinMap } = getTraceRecoveryConnectivityMaps(
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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,19 @@ test("bug-report-20260911T195723Z", () => {

solver.solve()

const v3v3Label = solver.netLabelToTraceSolver!.outputNetLabelPlacements.find(
(label) =>
label.netId === "V3V3" && label.pinIds.includes("schematic_port_141"),
)
const v3v3Connector = solver.netLabelToTraceSolver!.outputTraces.find(
(trace) => trace.mspPairId === "available-net-orientation-43-V3V3",
)

expect(v3v3Label?.orientation).toBe("y+")
expect(v3v3Connector).toBeUndefined()
const v3v3HostTrace = solver.netLabelToTraceSolver!.outputTraces.find(
(trace) => trace.pinIds.includes("schematic_port_141"),
)
expect(v3v3HostTrace?.tracePath).toContainEqual({ x: -6.5, y: -19 })
expect(solver).toMatchSolverSnapshot(import.meta.path)
})
20 changes: 10 additions & 10 deletions tests/examples/__snapshots__/example51.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading