@tscircuit/capacity-autorouter 0.0.8 → 0.0.9

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
@@ -4287,6 +4287,66 @@ var NetToPointPairsSolver = class extends BaseSolver {
4287
4287
  }
4288
4288
  };
4289
4289
 
4290
+ // lib/utils/convertHdRouteToSimplifiedRoute.ts
4291
+ var convertHdRouteToSimplifiedRoute = (hdRoute, layerCount) => {
4292
+ const result = [];
4293
+ if (hdRoute.route.length === 0) return result;
4294
+ const mapZToLayerName = (z) => {
4295
+ if (z < 0 || z >= layerCount) {
4296
+ throw new Error(`Invalid z "${z}" for layer count: ${layerCount}`);
4297
+ }
4298
+ if (z === 0) return "top";
4299
+ if (z === layerCount - 1) return "bottom";
4300
+ return `inner${z}`;
4301
+ };
4302
+ let currentLayerPoints = [];
4303
+ let currentZ = hdRoute.route[0].z;
4304
+ for (let i = 0; i < hdRoute.route.length; i++) {
4305
+ const point = hdRoute.route[i];
4306
+ if (point.z !== currentZ) {
4307
+ const layerName2 = mapZToLayerName(currentZ);
4308
+ for (const layerPoint of currentLayerPoints) {
4309
+ result.push({
4310
+ route_type: "wire",
4311
+ x: layerPoint.x,
4312
+ y: layerPoint.y,
4313
+ width: hdRoute.traceThickness,
4314
+ layer: layerName2
4315
+ });
4316
+ }
4317
+ const viaExists = hdRoute.vias.some(
4318
+ (via) => Math.abs(via.x - point.x) < 1e-3 && Math.abs(via.y - point.y) < 1e-3
4319
+ );
4320
+ if (viaExists) {
4321
+ const fromLayer = mapZToLayerName(point.z);
4322
+ const toLayer = mapZToLayerName(point.z);
4323
+ result.push({
4324
+ route_type: "via",
4325
+ x: point.x,
4326
+ y: point.y,
4327
+ from_layer: fromLayer,
4328
+ to_layer: toLayer
4329
+ });
4330
+ }
4331
+ currentLayerPoints = [point];
4332
+ currentZ = point.z;
4333
+ } else {
4334
+ currentLayerPoints.push(point);
4335
+ }
4336
+ }
4337
+ const layerName = mapZToLayerName(currentZ);
4338
+ for (const layerPoint of currentLayerPoints) {
4339
+ result.push({
4340
+ route_type: "wire",
4341
+ x: layerPoint.x,
4342
+ y: layerPoint.y,
4343
+ width: hdRoute.traceThickness,
4344
+ layer: layerName
4345
+ });
4346
+ }
4347
+ return result;
4348
+ };
4349
+
4290
4350
  // lib/solvers/CapacityMeshSolver/CapacityMeshSolver.ts
4291
4351
  var CapacityMeshSolver = class extends BaseSolver {
4292
4352
  constructor(srj, opts = {}) {
@@ -4508,60 +4568,15 @@ var CapacityMeshSolver = class extends BaseSolver {
4508
4568
  if (!this.solved || !this.highDensityRouteSolver) {
4509
4569
  throw new Error("Cannot get output before solving is complete");
4510
4570
  }
4511
- const traceIdToRoutes = {};
4512
- for (const route of this.highDensityRouteSolver.routes) {
4513
- const traceId = route.connectionName;
4514
- if (!traceIdToRoutes[traceId]) {
4515
- traceIdToRoutes[traceId] = [];
4516
- }
4517
- traceIdToRoutes[traceId].push(route);
4518
- }
4519
4571
  const traces = [];
4520
- for (const [traceId, routes] of Object.entries(traceIdToRoutes)) {
4521
- if (routes.length === 0) continue;
4522
- const originalConnectionName = this.getOriginalConnectionName(traceId);
4572
+ for (const hdRoute of this.highDensityRouteSolver.routes) {
4573
+ const pointPairConnName = hdRoute.connectionName;
4523
4574
  const trace = {
4524
4575
  type: "pcb_trace",
4525
- pcb_trace_id: traceId,
4526
- connection_name: originalConnectionName,
4527
- route: []
4576
+ pcb_trace_id: pointPairConnName,
4577
+ connection_name: this.getOriginalConnectionName(pointPairConnName),
4578
+ route: convertHdRouteToSimplifiedRoute(hdRoute, 2)
4528
4579
  };
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];
4546
- const nextLayerStr = point.z.toString();
4547
- if (nextLayerStr !== currentLayer) {
4548
- trace.route.push({
4549
- route_type: "via",
4550
- x: point.x,
4551
- y: point.y,
4552
- from_layer: this.mapLayer(currentLayer),
4553
- to_layer: this.mapLayer(nextLayerStr)
4554
- });
4555
- currentLayer = nextLayerStr;
4556
- }
4557
- trace.route.push({
4558
- route_type: "wire",
4559
- x: point.x,
4560
- y: point.y,
4561
- width: traceThickness,
4562
- layer: this.mapLayer(currentLayer)
4563
- });
4564
- }
4565
4580
  traces.push(trace);
4566
4581
  }
4567
4582
  return {