-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathrerouteCollidingTrace.ts
More file actions
85 lines (77 loc) · 2.76 KB
/
Copy pathrerouteCollidingTrace.ts
File metadata and controls
85 lines (77 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { Point } from "@tscircuit/math-utils"
import type { SolvedTracePath } from "../SchematicTraceLinesSolver/SchematicTraceLinesSolver"
import type { NetLabelPlacement } from "../NetLabelPlacementSolver/NetLabelPlacementSolver"
import { getRectBounds } from "../NetLabelPlacementSolver/SingleNetLabelPlacementSolver/geometry"
import type { InputProblem } from "lib/types/InputProblem"
import { findTraceViolationZone } from "./violation"
import { generateSnipAndReconnectCandidates } from "./trySnipAndReconnect"
import { generateFourPointDetourCandidates } from "./tryFourPointDetour"
import { simplifyPath } from "../TraceCleanupSolver/simplifyPath"
/**
* Generates a list of candidate rerouted paths for a given trace that is
* colliding with a net label.
*
* This function employs multiple strategies to propose alternative paths:
* 1. **Four-Point Detour:** Creates a rectangular detour around the label.
* 2. **Snip and Reconnect:** Attempts to remove the colliding segment and
* reconnect the trace around the obstacle.
*
* The candidates are generated with increasing padding based on `detourCount`
* to explore progressively wider detours.
*/
export const generateRerouteCandidates = ({
trace,
label,
paddingBuffer,
detourCount,
includeCornerDetours = false,
}: {
trace: SolvedTracePath
label: NetLabelPlacement
problem: InputProblem
paddingBuffer: number
detourCount: number
includeCornerDetours?: boolean
}): Point[][] => {
const initialTrace = { ...trace, tracePath: simplifyPath(trace.tracePath) }
if (trace.globalConnNetId === label.globalConnNetId) {
return [initialTrace.tracePath]
}
const labelBoundsRaw = getRectBounds(label.center, label.width, label.height)
const labelBounds = {
minX: labelBoundsRaw.minX,
minY: labelBoundsRaw.minY,
maxX: labelBoundsRaw.maxX,
maxY: labelBoundsRaw.maxY,
chipId: `netlabel-${label.netId}`,
}
const fourPointCandidates = generateFourPointDetourCandidates({
initialTrace,
label,
labelBounds,
paddingBuffer,
detourCount,
})
const effectivePadding = paddingBuffer + detourCount * paddingBuffer
const paddedLabelBounds = {
minX: labelBounds.minX - effectivePadding,
maxX: labelBounds.maxX + effectivePadding,
minY: labelBounds.minY - effectivePadding,
maxY: labelBounds.maxY + effectivePadding,
}
const { firstInsideIndex, lastInsideIndex } = findTraceViolationZone({
path: initialTrace.tracePath,
labelBounds,
paddedBounds: paddedLabelBounds,
})
const snipReconnectCandidates = generateSnipAndReconnectCandidates({
initialTrace,
firstInsideIndex,
lastInsideIndex,
includeCornerDetours,
labelBounds,
paddingBuffer,
detourCount,
})
return [...fourPointCandidates, ...snipReconnectCandidates]
}