From 0b78c466b244c399a9a38b6038b40158e0eca1b4 Mon Sep 17 00:00:00 2001 From: janisag07 Date: Tue, 17 Feb 2026 15:04:50 +0100 Subject: [PATCH] fix: skip MSP pair creation for net-label-only connections Net connections (netConnections) represent user-placed net labels that connect pins by name. These should only produce net labels, not traces. Previously, the MspConnectionPairSolver created MSP pairs for all nets including net-label-only connections, resulting in redundant traces drawn between pins that already had net labels. This change filters the queued nets so that only nets containing at least one pin with a direct connection produce MSP pairs. Pins connected solely via net labels now correctly receive only net label placements. Fixes tscircuit/schematic-trace-solver#79 --- .../MspConnectionPairSolver.ts | 15 +- .../examples/__snapshots__/example01.snap.svg | 9 +- .../examples/__snapshots__/example12.snap.svg | 60 ++++---- .../examples/__snapshots__/example13.snap.svg | 23 +-- .../examples/__snapshots__/example15.snap.svg | 56 +++++--- .../examples/__snapshots__/example16.snap.svg | 57 ++++---- .../examples/__snapshots__/example21.snap.svg | 133 +++++++++--------- .../examples/__snapshots__/example22.snap.svg | 46 +++--- .../MspConnectionPairSolver_repro1.test.ts | 4 +- ...hematicTracePipelineSolver_repro61.test.ts | 60 ++++++++ 10 files changed, 281 insertions(+), 182 deletions(-) create mode 100644 tests/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver_repro61.test.ts diff --git a/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts b/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts index 48b46c9..8fa458b 100644 --- a/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +++ b/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts @@ -74,7 +74,20 @@ export class MspConnectionPairSolver extends BaseSolver { } } - this.queuedDcNetIds = Object.keys(netConnMap.netMap) + // Only queue nets that have direct connections (traces). + // Nets connected solely via netConnections (net labels) should not + // produce MSP pairs – they receive net labels instead of traces. + const directNetIds = new Set(Object.keys(directConnMap.netMap)) + this.queuedDcNetIds = Object.keys(netConnMap.netMap).filter((netId) => { + // A net qualifies for tracing if at least one of its pins appears + // in the direct-connection map under the same global net. + const allIds = netConnMap.getIdsConnectedToNet(netId) as string[] + const pins = allIds.filter((id) => !!this.pinMap[id]) + return pins.some((pinId) => { + const dcNet = directConnMap.getNetConnectedToId(pinId) + return dcNet != null && directNetIds.has(dcNet) + }) + }) } override getConstructorParams(): ConstructorParameters< diff --git a/tests/examples/__snapshots__/example01.snap.svg b/tests/examples/__snapshots__/example01.snap.svg index 293bf05..8f364a3 100644 --- a/tests/examples/__snapshots__/example01.snap.svg +++ b/tests/examples/__snapshots__/example01.snap.svg @@ -49,6 +49,9 @@ y-" data-x="-4" data-y="-0.5" cx="67.72277227722776" cy="356.03960396039605" r=" + + + @@ -73,9 +76,6 @@ y-" data-x="-4" data-y="-0.5" cx="67.72277227722776" cy="356.03960396039605" r=" - - - @@ -94,6 +94,9 @@ y-" data-x="-4" data-y="-0.5" cx="67.72277227722776" cy="356.03960396039605" r=" + + + - + + + + - + diff --git a/tests/examples/__snapshots__/example15.snap.svg b/tests/examples/__snapshots__/example15.snap.svg index fa7b2fb..8bf97bb 100644 --- a/tests/examples/__snapshots__/example15.snap.svg +++ b/tests/examples/__snapshots__/example15.snap.svg @@ -335,13 +335,25 @@ y-" data-x="-2.025" data-y="-2.7" cx="318.5204755614267" cy="526.0237780713342" - + - + - + + + + + + + + + + + + + @@ -812,28 +824,16 @@ y-" data-x="-2.025" data-y="-2.7" cx="318.5204755614267" cy="526.0237780713342" - - - - - - - + - + - + - - - - - - - + @@ -890,13 +890,25 @@ y-" data-x="-2.025" data-y="-2.7" cx="318.5204755614267" cy="526.0237780713342" - + + + + + + + + + + + + + - + - +