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
8 changes: 8 additions & 0 deletions lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export class LongDistancePairSolver extends BaseSolver {

// 1. Create initial maps and sets for efficient lookup
const primaryConnectedPinIds = new Set<PinId>()
const netsWithPrimaryPairs = new Set<string>()
for (const pair of primaryMspConnectionPairs) {
primaryConnectedPinIds.add(pair.pins[0].pinId)
primaryConnectedPinIds.add(pair.pins[1].pinId)
netsWithPrimaryPairs.add(pair.globalConnNetId)
}

const { netConnMap } = getConnectivityMapsFromInputProblem(inputProblem)
Expand All @@ -74,6 +76,12 @@ export class LongDistancePairSolver extends BaseSolver {
const addedPairKeys = new Set<string>()

for (const netId of Object.keys(netConnMap.netMap)) {
// Long-distance routing only "fills in" pins on a net that is already
// partially routed via a direct connection. Nets that exist only as
// net-label connections should remain label-only — drawing extra traces
// here is the bug seen in repro61 (issue #79).
if (!netsWithPrimaryPairs.has(netId)) continue

const allPinIdsInNet = netConnMap.getIdsConnectedToNet(netId)
if (allPinIdsInNet.length < 2) continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export class MspConnectionPairSolver extends BaseSolver {

const dcNetId = this.queuedDcNetIds.shift()!

const allIds = this.globalConnMap.getIdsConnectedToNet(dcNetId) as string[]
// Only pins that share a *direct* connection should be paired into a
// routed trace. Pins linked only via a net connection (net label) are
// expressed visually by the label itself, not by an MSP-routed trace.
// See repro61 (tscircuit/schematic-trace-solver#79).
const allIds = this.dcConnMap.getIdsConnectedToNet(dcNetId) as string[]
const directlyConnectedPins = allIds.filter((id) => !!this.pinMap[id])

if (directlyConnectedPins.length <= 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const getConnectivityMapsFromInputProblem = (
])
}

const netConnMap = new ConnectivityMap(directConnMap.netMap)
// ConnectivityMap stores the netMap by reference; if we passed
// `directConnMap.netMap` directly, subsequent `netConnMap.addConnections`
// calls would mutate `directConnMap` too, polluting the "direct only" view.
// Clone so the two maps stay independent. (See repro61, tscircuit/schematic-trace-solver#79.)
const netConnMap = new ConnectivityMap(structuredClone(directConnMap.netMap))

for (const netConn of inputProblem.netConnections) {
netConnMap.addConnections([[netConn.netId, ...netConn.pinIds]])
Expand Down
75 changes: 40 additions & 35 deletions tests/examples/__snapshots__/example01.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