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
29 changes: 25 additions & 4 deletions lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { distance } from "@tscircuit/math-utils"
import { getConnectivityMapsFromInputProblem } from "lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem"
import type { MspConnectionPair } from "lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver"
import type {
Expand All @@ -15,10 +16,7 @@ import type { ConnectivityMap } from "connectivity-map"
import { arePinsInDifferentSchematicSections } from "../../utils/arePinsInDifferentSchematicSections"

const NEAREST_NEIGHBOR_COUNT = 3

const distance = (p1: InputPin, p2: InputPin) => {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2))
}
const MAX_NAMED_NET_TRACE_DISTANCE = 7.5

export class LongDistancePairSolver extends BaseSolver {
public solvedLongDistanceTraces: SolvedTracePath[] = []
Expand Down Expand Up @@ -72,6 +70,10 @@ export class LongDistancePairSolver extends BaseSolver {
[InputPin & { chipId: string }, InputPin & { chipId: string }]
> = []
const addedPairKeys = new Set<string>()
const maxNamedNetTraceDistance = Math.max(
inputProblem.maxMspPairDistance ?? 1,
MAX_NAMED_NET_TRACE_DISTANCE,
)

for (const netId of Object.keys(netConnMap.netMap)) {
const allPinIdsInNet = netConnMap.getIdsConnectedToNet(netId)
Expand All @@ -90,6 +92,25 @@ export class LongDistancePairSolver extends BaseSolver {
.flatMap((otherPinId) => {
const targetPin = pinMap.get(otherPinId)
if (!targetPin) return [] // Gracefully handle missing pins
const isDirectConnection = inputProblem.directConnections.some(
({ pinIds }) =>
pinIds.includes(sourcePin.pinId) &&
pinIds.includes(targetPin.pinId),
)
const isNamedNet = inputProblem.netConnections.some(
({ pinIds }) =>
pinIds.includes(sourcePin.pinId) &&
pinIds.includes(targetPin.pinId),
)
const orthogonalDistance =
Math.abs(sourcePin.x - targetPin.x) +
Math.abs(sourcePin.y - targetPin.y)
// Use net labels instead of routing long connections across the schematic.
const shouldUseNetLabels =
isNamedNet &&
!isDirectConnection &&
orthogonalDistance > maxNamedNetTraceDistance
if (shouldUseNetLabels) return []
return [
{
pin: targetPin,
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.
84 changes: 43 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.
94 changes: 48 additions & 46 deletions tests/repros/__snapshots__/repro-atmega328p-fault-pullup.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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading