@tscircuit/capacity-autorouter 0.0.6 → 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.d.ts CHANGED
@@ -32,11 +32,13 @@ interface SimpleRouteConnection {
32
32
  x: number;
33
33
  y: number;
34
34
  layer: string;
35
+ pcb_port_id?: string;
35
36
  }>;
36
37
  }
37
38
  type SimplifiedPcbTraces = Array<{
38
39
  type: "pcb_trace";
39
40
  pcb_trace_id: TraceId;
41
+ connection_name: string;
40
42
  route: Array<{
41
43
  route_type: "wire";
42
44
  x: number;
@@ -822,6 +824,18 @@ declare class CapacityMeshSolver extends BaseSolver {
822
824
  * Simplifies a route by merging consecutive points along the same line
823
825
  */
824
826
  private simplifyRoute;
827
+ /**
828
+ * Maps numeric layer to named layer
829
+ * @param layer Numeric layer (0, 1, etc)
830
+ * @returns Named layer ("top", "bottom", etc)
831
+ */
832
+ private mapLayer;
833
+ /**
834
+ * Get original connection name from connection name with MST suffix
835
+ * @param mstConnectionName The MST-suffixed connection name (e.g. "connection1_mst0")
836
+ * @returns The original connection name (e.g. "connection1")
837
+ */
838
+ private getOriginalConnectionName;
825
839
  /**
826
840
  * Returns the SimpleRouteJson with routes converted to SimplifiedPcbTraces
827
841
  */
package/dist/index.js CHANGED
@@ -4477,6 +4477,30 @@ var CapacityMeshSolver = class extends BaseSolver {
4477
4477
  result.push(points[points.length - 1]);
4478
4478
  return result;
4479
4479
  }
4480
+ /**
4481
+ * Maps numeric layer to named layer
4482
+ * @param layer Numeric layer (0, 1, etc)
4483
+ * @returns Named layer ("top", "bottom", etc)
4484
+ */
4485
+ mapLayer(layer) {
4486
+ switch (layer) {
4487
+ case "0":
4488
+ return "top";
4489
+ case "1":
4490
+ return "bottom";
4491
+ default:
4492
+ return `layer${layer}`;
4493
+ }
4494
+ }
4495
+ /**
4496
+ * Get original connection name from connection name with MST suffix
4497
+ * @param mstConnectionName The MST-suffixed connection name (e.g. "connection1_mst0")
4498
+ * @returns The original connection name (e.g. "connection1")
4499
+ */
4500
+ getOriginalConnectionName(mstConnectionName) {
4501
+ const match = mstConnectionName.match(/^(.+?)_mst\d+$/);
4502
+ return match ? match[1] : mstConnectionName;
4503
+ }
4480
4504
  /**
4481
4505
  * Returns the SimpleRouteJson with routes converted to SimplifiedPcbTraces
4482
4506
  */
@@ -4484,25 +4508,49 @@ var CapacityMeshSolver = class extends BaseSolver {
4484
4508
  if (!this.solved || !this.highDensityRouteSolver) {
4485
4509
  throw new Error("Cannot get output before solving is complete");
4486
4510
  }
4487
- const traces = [];
4511
+ const traceIdToRoutes = {};
4488
4512
  for (const route of this.highDensityRouteSolver.routes) {
4489
- const simplifiedRoute = this.simplifyRoute(route.route);
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);
4490
4523
  const trace = {
4491
4524
  type: "pcb_trace",
4492
- pcb_trace_id: route.connectionName,
4525
+ pcb_trace_id: traceId,
4526
+ connection_name: originalConnectionName,
4493
4527
  route: []
4494
4528
  };
4495
- let currentLayer = simplifiedRoute[0]?.z.toString() || "0";
4496
- for (let i = 0; i < simplifiedRoute.length; i++) {
4497
- 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];
4498
4546
  const nextLayerStr = point.z.toString();
4499
4547
  if (nextLayerStr !== currentLayer) {
4500
4548
  trace.route.push({
4501
4549
  route_type: "via",
4502
4550
  x: point.x,
4503
4551
  y: point.y,
4504
- from_layer: currentLayer,
4505
- to_layer: nextLayerStr
4552
+ from_layer: this.mapLayer(currentLayer),
4553
+ to_layer: this.mapLayer(nextLayerStr)
4506
4554
  });
4507
4555
  currentLayer = nextLayerStr;
4508
4556
  }
@@ -4510,8 +4558,8 @@ var CapacityMeshSolver = class extends BaseSolver {
4510
4558
  route_type: "wire",
4511
4559
  x: point.x,
4512
4560
  y: point.y,
4513
- width: route.traceThickness || this.highDensityRouteSolver.defaultTraceThickness,
4514
- layer: currentLayer
4561
+ width: traceThickness,
4562
+ layer: this.mapLayer(currentLayer)
4515
4563
  });
4516
4564
  }
4517
4565
  traces.push(trace);