@tscircuit/capacity-autorouter 0.0.7 → 0.0.8

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/dist/index.js CHANGED
@@ -4508,21 +4508,41 @@ var CapacityMeshSolver = class extends BaseSolver {
4508
4508
  if (!this.solved || !this.highDensityRouteSolver) {
4509
4509
  throw new Error("Cannot get output before solving is complete");
4510
4510
  }
4511
- const traces = [];
4511
+ const traceIdToRoutes = {};
4512
4512
  for (const route of this.highDensityRouteSolver.routes) {
4513
- const simplifiedRoute = this.simplifyRoute(route.route);
4514
- const originalConnectionName = this.getOriginalConnectionName(
4515
- route.connectionName
4516
- );
4513
+ const traceId = route.connectionName;
4514
+ if (!traceIdToRoutes[traceId]) {
4515
+ traceIdToRoutes[traceId] = [];
4516
+ }
4517
+ traceIdToRoutes[traceId].push(route);
4518
+ }
4519
+ const traces = [];
4520
+ for (const [traceId, routes] of Object.entries(traceIdToRoutes)) {
4521
+ if (routes.length === 0) continue;
4522
+ const originalConnectionName = this.getOriginalConnectionName(traceId);
4517
4523
  const trace = {
4518
4524
  type: "pcb_trace",
4519
- pcb_trace_id: route.connectionName,
4525
+ pcb_trace_id: traceId,
4520
4526
  connection_name: originalConnectionName,
4521
4527
  route: []
4522
4528
  };
4523
- let currentLayer = simplifiedRoute[0]?.z.toString() || "0";
4524
- for (let i = 0; i < simplifiedRoute.length; i++) {
4525
- const point = simplifiedRoute[i];
4529
+ const traceThickness = routes[0].traceThickness || this.highDensityRouteSolver.defaultTraceThickness;
4530
+ const allPoints = [];
4531
+ routes.forEach((route, routeIndex) => {
4532
+ const simplifiedRoute = this.simplifyRoute(route.route);
4533
+ simplifiedRoute.forEach((point, pointIndex) => {
4534
+ allPoints.push({ ...point, routeIndex, pointIndex });
4535
+ });
4536
+ });
4537
+ if (allPoints.length === 0) continue;
4538
+ allPoints.sort((a, b) => {
4539
+ if (a.z !== b.z) return a.z - b.z;
4540
+ if (a.x !== b.x) return a.x - b.x;
4541
+ return a.y - b.y;
4542
+ });
4543
+ let currentLayer = allPoints[0].z.toString();
4544
+ for (let i = 0; i < allPoints.length; i++) {
4545
+ const point = allPoints[i];
4526
4546
  const nextLayerStr = point.z.toString();
4527
4547
  if (nextLayerStr !== currentLayer) {
4528
4548
  trace.route.push({
@@ -4538,7 +4558,7 @@ var CapacityMeshSolver = class extends BaseSolver {
4538
4558
  route_type: "wire",
4539
4559
  x: point.x,
4540
4560
  y: point.y,
4541
- width: route.traceThickness || this.highDensityRouteSolver.defaultTraceThickness,
4561
+ width: traceThickness,
4542
4562
  layer: this.mapLayer(currentLayer)
4543
4563
  });
4544
4564
  }