@tscircuit/capacity-autorouter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
File without changes
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # capacity-node-autorouter
2
+
3
+ A high-density PCB autorouter library for node.js and TypeScript projects. Part of the [tscircuit project](https://github.com/tscircuit/tscircuit) · [discord](https://tscircuit.com/join) · [twitter](https://x.com/seveibar) · [try tscircuit online](https://tscircuit.com)
4
+
5
+ Check out this [short youtube explanation of this autorouter](https://youtu.be/MmTk0806fAo)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ bun add capacity-node-autorouter
11
+ ```
12
+
13
+ ## Usage as a Library
14
+
15
+ ### Basic Usage
16
+
17
+ ```typescript
18
+ import { CapacityMeshSolver } from "capacity-node-autorouter"
19
+
20
+ // Create a solver with SimpleRouteJson input
21
+ const solver = new CapacityMeshSolver(simpleRouteJson)
22
+
23
+ // Run the solver until completion
24
+ while (!solver.solved && !solver.failed) {
25
+ solver.step()
26
+ }
27
+
28
+ // Check if solving was successful
29
+ if (solver.failed) {
30
+ console.error("Routing failed:", solver.error)
31
+ } else {
32
+ // Get the routing results as SimpleRouteJson with traces
33
+ const resultWithRoutes = solver.getOutputSimpleRouteJson()
34
+
35
+ // Use the resulting routes in your application
36
+ console.log(
37
+ `Successfully routed ${resultWithRoutes.traces?.length} connections`
38
+ )
39
+ }
40
+ ```
41
+
42
+ ### Input Format: SimpleRouteJson
43
+
44
+ The input to the autorouter is a `SimpleRouteJson` object with the following structure:
45
+
46
+ ```typescript
47
+ interface SimpleRouteJson {
48
+ layerCount: number
49
+ minTraceWidth: number
50
+ obstacles: Obstacle[]
51
+ connections: Array<SimpleRouteConnection>
52
+ bounds: { minX: number; maxX: number; minY: number; maxY: number }
53
+ traces?: SimplifiedPcbTraces // Optional for input
54
+ }
55
+
56
+ interface Obstacle {
57
+ type: "rect"
58
+ layers: string[]
59
+ center: { x: number; y: number }
60
+ width: number
61
+ height: number
62
+ connectedTo: string[] // TraceIds
63
+ }
64
+
65
+ interface SimpleRouteConnection {
66
+ name: string
67
+ pointsToConnect: Array<{ x: number; y: number; layer: string }>
68
+ }
69
+ ```
70
+
71
+ ### Output Format
72
+
73
+ The `getOutputSimpleRouteJson()` method returns the original `SimpleRouteJson` with a populated `traces` property. The traces are represented as `SimplifiedPcbTraces`:
74
+
75
+ ```typescript
76
+ type SimplifiedPcbTraces = Array<{
77
+ type: "pcb_trace"
78
+ pcb_trace_id: string // TraceId
79
+ route: Array<
80
+ | {
81
+ route_type: "wire"
82
+ x: number
83
+ y: number
84
+ width: number
85
+ layer: string
86
+ }
87
+ | {
88
+ route_type: "via"
89
+ x: number
90
+ y: number
91
+ to_layer: string
92
+ from_layer: string
93
+ }
94
+ >
95
+ }>
96
+ ```
97
+
98
+ ### Advanced Configuration
99
+
100
+ You can provide optional configuration parameters to the solver:
101
+
102
+ ```typescript
103
+ const solver = new CapacityMeshSolver(simpleRouteJson, {
104
+ // Optional: Manually set capacity planning depth (otherwise automatically calculated)
105
+ capacityDepth: 7,
106
+
107
+ // Optional: Set the target minimum capacity for automatic depth calculation
108
+ // Lower values result in finer subdivisions (higher depth)
109
+ targetMinCapacity: 0.5
110
+ })
111
+ ```
112
+
113
+ By default, the solver will automatically calculate the optimal `capacityDepth` to achieve a target minimum capacity of 0.5 based on the board dimensions. This automatic calculation ensures that the smallest subdivision cells have an appropriate capacity for routing.
114
+
115
+ ### Visualization Support
116
+
117
+ For debugging or interactive applications, you can use the `visualize()` method to get a visualization of the current routing state:
118
+
119
+ ```typescript
120
+ // Get visualization data that can be rendered with graphics-debug
121
+ const visualization = solver.visualize()
122
+ ```
123
+
124
+ ## System Architecture
125
+
126
+ ```mermaid
127
+ flowchart LR
128
+ subgraph HDR[High Density Route Solver]
129
+ T1[ ] & T2[ ] & T3[ ] & T4[ ] & T5[ ] & T6[ ] & T7[ ] & T8[ ] & T9[ ]
130
+ subgraph IS[HyperSingleIntraNodeSolver / SingleIntraNodeSolver]
131
+ N1[ ] --> N2[ ]
132
+ N2 --> N3[ ]
133
+ N3 --> N4[ ]
134
+ N4 --> N5[ ]
135
+ N5 --> N6[ ]
136
+ N6 --> N7[ ]
137
+ N7 --> N8[ ]
138
+ N8 --> N9[ ]
139
+ end
140
+ subgraph SHDR[SingleHighDensityRouteSolver]
141
+ end
142
+ T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 --> IS
143
+ IS --> SHDR
144
+ end
145
+
146
+ NS[Node Solver] --> ES[Edge Solver]
147
+ ES --> MES[Mesh Edge Solver]
148
+ MES --> CPS[Capacity Planning Solver]
149
+ CPS --> EPSS[Edge to Port Segment Solver]
150
+ EPSS --> S2P[Segment to Point Solver]
151
+ S2P --> SPO[Segment Point Optimizer]
152
+ SPO --> HDR
153
+ ```
154
+
155
+ The autorouter uses a multi-step approach that includes:
156
+
157
+ 1. **Node Solving**: Determines node placement
158
+ 2. **Edge Solving**: Creates connections between nodes
159
+ 3. **Mesh Edge Solving**: Refines connection patterns
160
+ 4. **Capacity Planning**: Allocates routing resources
161
+ 5. **Edge to Port Segment Solving**: Connects segments to ports
162
+ 6. **Segment to Point Solving**: Converts segments to exact point locations
163
+ 7. **Segment Point Optimization**: Optimizes point placements for better routing
164
+ 8. **High Density Routing**: Final detailed routing with obstacle avoidance
165
+
166
+ ## Development
167
+
168
+ To work on this library:
169
+
170
+ ```bash
171
+ # Install dependencies
172
+ bun install
173
+
174
+ # Start the interactive development environment
175
+ bun run start
176
+
177
+ # Run tests
178
+ bun test
179
+
180
+ # Build the library
181
+ bun run build
182
+ ```
183
+
184
+ ## License
185
+
186
+ See the [LICENSE](LICENSE) file for details.