@tscircuit/capacity-autorouter 0.0.50 → 0.0.51

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
@@ -559,6 +559,10 @@ declare class SingleHighDensityRouteSolver extends BaseSolver {
559
559
  debug_nodesTooCloseToObstacle: Set<string>;
560
560
  debug_nodePathToParentIntersectsObstacle: Set<string>;
561
561
  debugEnabled: boolean;
562
+ initialNodeGridOffset: {
563
+ x: number;
564
+ y: number;
565
+ };
562
566
  constructor(opts: {
563
567
  connectionName: string;
564
568
  obstacleRoutes: HighDensityIntraNodeRoute$1[];
@@ -1225,6 +1229,7 @@ declare class UnravelSectionSolver extends BaseSolver {
1225
1229
  colorMap: Record<string, string>;
1226
1230
  tunedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1227
1231
  MAX_CANDIDATES: number;
1232
+ iterationsSinceImprovement: number;
1228
1233
  selectedCandidateIndex: number | "best" | "original" | null;
1229
1234
  queuedOrExploredCandidatePointModificationHashes: Set<string>;
1230
1235
  constructor(params: {
package/dist/index.js CHANGED
@@ -2205,6 +2205,7 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
2205
2205
  debug_nodesTooCloseToObstacle;
2206
2206
  debug_nodePathToParentIntersectsObstacle;
2207
2207
  debugEnabled = true;
2208
+ initialNodeGridOffset;
2208
2209
  constructor(opts) {
2209
2210
  super();
2210
2211
  this.bounds = opts.bounds;
@@ -2250,11 +2251,18 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
2250
2251
  if (this.futureConnections && this.futureConnections.length === 0 && this.obstacleRoutes.length === 0) {
2251
2252
  this.handleSimpleCases();
2252
2253
  }
2254
+ const initialNodePosition = {
2255
+ x: Math.round(opts.A.x / (this.cellStep / 2)) * (this.cellStep / 2),
2256
+ y: Math.round(opts.A.y / (this.cellStep / 2)) * (this.cellStep / 2)
2257
+ };
2258
+ this.initialNodeGridOffset = {
2259
+ x: initialNodePosition.x - Math.round(opts.A.x / this.cellStep) * this.cellStep,
2260
+ y: initialNodePosition.y - Math.round(opts.A.y / this.cellStep) * this.cellStep
2261
+ };
2253
2262
  this.candidates = new SingleRouteCandidatePriorityQueue([
2254
2263
  {
2255
2264
  ...opts.A,
2256
- x: Math.floor(opts.A.x / this.cellStep) * this.cellStep,
2257
- y: Math.floor(opts.A.y / this.cellStep) * this.cellStep,
2265
+ ...initialNodePosition,
2258
2266
  z: opts.A.z ?? 0,
2259
2267
  g: 0,
2260
2268
  h: 0,
@@ -2317,7 +2325,7 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
2317
2325
  }
2318
2326
  }
2319
2327
  for (const via of route.vias) {
2320
- if (distance(node, via) < this.viaDiameter / 2 + margin) {
2328
+ if (distance(node, via) < this.viaDiameter / 2 + this.traceThickness / 2 + margin) {
2321
2329
  return true;
2322
2330
  }
2323
2331
  }
@@ -2484,7 +2492,13 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
2484
2492
  goalDist,
2485
2493
  currentNode.z === this.B.z
2486
2494
  );
2487
- if (goalDist <= this.cellStep * Math.SQRT2 && currentNode.z === this.B.z) {
2495
+ if (goalDist <= this.cellStep * Math.SQRT2 && currentNode.z === this.B.z && // Make sure the last segment doesn't intersect an obstacle
2496
+ !this.doesPathToParentIntersectObstacle({
2497
+ ...currentNode,
2498
+ parent: currentNode,
2499
+ x: this.B.x,
2500
+ y: this.B.y
2501
+ })) {
2488
2502
  this.solved = true;
2489
2503
  this.setSolvedPath(currentNode);
2490
2504
  }
@@ -2539,8 +2553,8 @@ z: ${this.B.z}`,
2539
2553
  if (this.debug_nodePathToParentIntersectsObstacle.has(nodeKey)) continue;
2540
2554
  graphics.rects.push({
2541
2555
  center: {
2542
- x: x + z * this.cellStep / 20,
2543
- y: y + z * this.cellStep / 20
2556
+ x: x + this.initialNodeGridOffset.x + z * this.cellStep / 20,
2557
+ y: y + this.initialNodeGridOffset.y + z * this.cellStep / 20
2544
2558
  },
2545
2559
  fill: z === 0 ? `rgba(255,0,255,${0.3 - i / this.debug_exploredNodesOrdered.length * 0.2})` : `rgba(0,0,255,${0.3 - i / this.debug_exploredNodesOrdered.length * 0.2})`,
2546
2560
  width: this.cellStep * 0.9,
@@ -5784,11 +5798,13 @@ var UnravelSectionSolver = class extends BaseSolver {
5784
5798
  colorMap;
5785
5799
  tunedNodeCapacityMap;
5786
5800
  MAX_CANDIDATES = 500;
5801
+ iterationsSinceImprovement = 0;
5787
5802
  selectedCandidateIndex = null;
5788
5803
  queuedOrExploredCandidatePointModificationHashes = /* @__PURE__ */ new Set();
5789
5804
  constructor(params) {
5790
5805
  super();
5791
5806
  this.MUTABLE_HOPS = params.MUTABLE_HOPS ?? this.MUTABLE_HOPS;
5807
+ this.MAX_ITERATIONS = 5e4;
5792
5808
  this.nodeMap = params.nodeMap;
5793
5809
  this.dedupedSegments = params.dedupedSegments;
5794
5810
  if (params.dedupedSegmentMap) {
@@ -6183,6 +6199,7 @@ var UnravelSectionSolver = class extends BaseSolver {
6183
6199
  }
6184
6200
  _step() {
6185
6201
  const candidate = this.candidates.shift();
6202
+ this.iterationsSinceImprovement++;
6186
6203
  if (!candidate) {
6187
6204
  this.solved = true;
6188
6205
  return;
@@ -6190,6 +6207,7 @@ var UnravelSectionSolver = class extends BaseSolver {
6190
6207
  this.lastProcessedCandidate = candidate;
6191
6208
  if (candidate.f < (this.bestCandidate?.f ?? Infinity)) {
6192
6209
  this.bestCandidate = candidate;
6210
+ this.iterationsSinceImprovement = 0;
6193
6211
  }
6194
6212
  this.getNeighbors(candidate).forEach((neighbor) => {
6195
6213
  const isPartialHashExplored = this.queuedOrExploredCandidatePointModificationHashes.has(
@@ -6591,8 +6609,7 @@ var UnravelMultiSectionSolver = class extends BaseSolver {
6591
6609
  }
6592
6610
  this.activeSolver.step();
6593
6611
  const { bestCandidate, originalCandidate, lastProcessedCandidate } = this.activeSolver;
6594
- const giveUpFactor = 1 + 4 * (1 - Math.min(1, this.activeSolver.iterations / 40));
6595
- const shouldEarlyStop = lastProcessedCandidate && lastProcessedCandidate.g > bestCandidate.g * giveUpFactor;
6612
+ const shouldEarlyStop = this.activeSolver.iterationsSinceImprovement > 200;
6596
6613
  if (this.activeSolver.solved || shouldEarlyStop) {
6597
6614
  const foundBetterSolution = bestCandidate && bestCandidate.g < originalCandidate.g;
6598
6615
  if (foundBetterSolution) {