@tscircuit/capacity-autorouter 0.0.15 → 0.0.17

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
@@ -92,6 +92,7 @@ declare class BaseSolver {
92
92
  iterations: number;
93
93
  progress: number;
94
94
  error: string | null;
95
+ failedSubSolvers?: BaseSolver[];
95
96
  /** DO NOT OVERRIDE! Override _step() instead */
96
97
  step(): void;
97
98
  _step(): void;
@@ -473,7 +474,7 @@ declare class SingleHighDensityRouteSolver extends BaseSolver {
473
474
  handleSimpleCases(): void;
474
475
  get viaPenaltyDistance(): number;
475
476
  isNodeTooCloseToObstacle(node: Node, margin?: number, isVia?: boolean): boolean;
476
- isNodeTooCloseToEdge(node: Node): boolean;
477
+ isNodeTooCloseToEdge(node: Node, isVia?: boolean): boolean;
477
478
  doesPathToParentIntersectObstacle(node: Node): boolean;
478
479
  computeH(node: Node): number;
479
480
  computeG(node: Node): number;
@@ -504,11 +505,12 @@ declare class IntraNodeRouteSolver extends BaseSolver {
504
505
  }[];
505
506
  totalConnections: number;
506
507
  solvedRoutes: HighDensityIntraNodeRoute[];
507
- failedSolvers: SingleHighDensityRouteSolver[];
508
+ failedSubSolvers: SingleHighDensityRouteSolver[];
508
509
  hyperParameters: Partial<HighDensityHyperParameters>;
509
510
  minDistBetweenEnteringPoints: number;
510
511
  activeSolver: SingleHighDensityRouteSolver | null;
511
512
  connMap?: ConnectivityMap;
513
+ get failedSolvers(): SingleHighDensityRouteSolver[];
512
514
  constructor(params: {
513
515
  nodeWithPortPoints: NodeWithPortPoints;
514
516
  colorMap?: Record<string, string>;
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ var BaseSolver = class {
43
43
  iterations = 0;
44
44
  progress = 0;
45
45
  error = null;
46
+ failedSubSolvers;
46
47
  /** DO NOT OVERRIDE! Override _step() instead */
47
48
  step() {
48
49
  if (this.solved) return;
@@ -1809,9 +1810,15 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
1809
1810
  }
1810
1811
  return false;
1811
1812
  }
1812
- isNodeTooCloseToEdge(node) {
1813
- const viaRadius = this.viaDiameter / 2;
1814
- return node.x < this.bounds.minX + viaRadius || node.x > this.bounds.maxX - viaRadius || node.y < this.bounds.minY + viaRadius || node.y > this.bounds.maxY - viaRadius;
1813
+ isNodeTooCloseToEdge(node, isVia) {
1814
+ const margin = isVia ? this.viaDiameter / 2 : this.obstacleMargin;
1815
+ const tooClose = node.x < this.bounds.minX + margin || node.x > this.bounds.maxX - margin || node.y < this.bounds.minY + margin || node.y > this.bounds.maxY - margin;
1816
+ if (tooClose && !isVia) {
1817
+ if (distance(node, this.B) < margin * 2) {
1818
+ return false;
1819
+ }
1820
+ }
1821
+ return tooClose;
1815
1822
  }
1816
1823
  doesPathToParentIntersectObstacle(node) {
1817
1824
  const parent = node.parent;
@@ -1865,6 +1872,10 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
1865
1872
  this.exploredNodes.add(neighborKey);
1866
1873
  continue;
1867
1874
  }
1875
+ if (this.isNodeTooCloseToEdge(neighbor, false)) {
1876
+ this.exploredNodes.add(neighborKey);
1877
+ continue;
1878
+ }
1868
1879
  if (this.doesPathToParentIntersectObstacle(neighbor)) {
1869
1880
  this.debug_nodePathToParentIntersectsObstacle.add(neighborKey);
1870
1881
  this.exploredNodes.add(neighborKey);
@@ -1883,9 +1894,9 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
1883
1894
  };
1884
1895
  if (!this.exploredNodes.has(this.getNodeKey(viaNeighbor)) && !this.isNodeTooCloseToObstacle(
1885
1896
  viaNeighbor,
1886
- this.viaDiameter / 2 + this.obstacleMargin,
1897
+ this.viaDiameter / 2 + this.obstacleMargin / 2,
1887
1898
  true
1888
- ) && !this.isNodeTooCloseToEdge(viaNeighbor)) {
1899
+ ) && !this.isNodeTooCloseToEdge(viaNeighbor, true)) {
1889
1900
  viaNeighbor.g = this.computeG(viaNeighbor);
1890
1901
  viaNeighbor.h = this.computeH(viaNeighbor);
1891
1902
  viaNeighbor.f = this.computeF(viaNeighbor.g, viaNeighbor.h);
@@ -1977,13 +1988,15 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
1977
1988
  graphics.points.push({
1978
1989
  x: this.A.x,
1979
1990
  y: this.A.y,
1980
- label: "Input A",
1991
+ label: `Input A
1992
+ z: ${this.A.z}`,
1981
1993
  color: "orange"
1982
1994
  });
1983
1995
  graphics.points.push({
1984
1996
  x: this.B.x,
1985
1997
  y: this.B.y,
1986
- label: "Input B",
1998
+ label: `Input B
1999
+ z: ${this.B.z}`,
1987
2000
  color: "orange"
1988
2001
  });
1989
2002
  graphics.lines.push({
@@ -2219,11 +2232,15 @@ var IntraNodeRouteSolver = class extends BaseSolver {
2219
2232
  unsolvedConnections;
2220
2233
  totalConnections;
2221
2234
  solvedRoutes;
2222
- failedSolvers;
2235
+ failedSubSolvers;
2223
2236
  hyperParameters;
2224
2237
  minDistBetweenEnteringPoints;
2225
2238
  activeSolver = null;
2226
2239
  connMap;
2240
+ // Legacy compat
2241
+ get failedSolvers() {
2242
+ return this.failedSubSolvers;
2243
+ }
2227
2244
  constructor(params) {
2228
2245
  const { nodeWithPortPoints, colorMap } = params;
2229
2246
  super();
@@ -2231,7 +2248,7 @@ var IntraNodeRouteSolver = class extends BaseSolver {
2231
2248
  this.colorMap = colorMap ?? {};
2232
2249
  this.solvedRoutes = [];
2233
2250
  this.hyperParameters = params.hyperParameters ?? {};
2234
- this.failedSolvers = [];
2251
+ this.failedSubSolvers = [];
2235
2252
  this.connMap = params.connMap;
2236
2253
  const unsolvedConnectionsMap = /* @__PURE__ */ new Map();
2237
2254
  for (const { connectionName, x, y, z } of nodeWithPortPoints.portPoints) {
@@ -2292,9 +2309,9 @@ var IntraNodeRouteSolver = class extends BaseSolver {
2292
2309
  this.solvedRoutes.push(this.activeSolver.solvedPath);
2293
2310
  this.activeSolver = null;
2294
2311
  } else if (this.activeSolver.failed) {
2295
- this.failedSolvers.push(this.activeSolver);
2312
+ this.failedSubSolvers.push(this.activeSolver);
2296
2313
  this.activeSolver = null;
2297
- this.error = this.failedSolvers.map((s) => s.error).join("\n");
2314
+ this.error = this.failedSubSolvers.map((s) => s.error).join("\n");
2298
2315
  this.failed = true;
2299
2316
  }
2300
2317
  return;
@@ -2302,7 +2319,7 @@ var IntraNodeRouteSolver = class extends BaseSolver {
2302
2319
  const unsolvedConnection = this.unsolvedConnections.pop();
2303
2320
  this.progress = this.computeProgress();
2304
2321
  if (!unsolvedConnection) {
2305
- this.solved = this.failedSolvers.length === 0;
2322
+ this.solved = this.failedSubSolvers.length === 0;
2306
2323
  return;
2307
2324
  }
2308
2325
  if (unsolvedConnection.points.length === 1) {
@@ -2373,6 +2390,20 @@ var IntraNodeRouteSolver = class extends BaseSolver {
2373
2390
  }
2374
2391
  }
2375
2392
  }
2393
+ const bounds = getBoundsFromNodeWithPortPoints(this.nodeWithPortPoints);
2394
+ const { minX, minY, maxX, maxY } = bounds;
2395
+ graphics.lines.push({
2396
+ points: [
2397
+ { x: minX, y: minY },
2398
+ { x: maxX, y: minY },
2399
+ { x: maxX, y: maxY },
2400
+ { x: minX, y: maxY },
2401
+ { x: minX, y: minY }
2402
+ ],
2403
+ strokeColor: "rgba(255, 0, 0, 0.25)",
2404
+ strokeDash: "4 4",
2405
+ layer: "border"
2406
+ });
2376
2407
  return graphics;
2377
2408
  }
2378
2409
  };