@tscircuit/capacity-autorouter 0.0.47 → 0.0.49

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
@@ -8358,26 +8358,59 @@ var SingleSimplifiedPathSolver5 = class extends SingleSimplifiedPathSolver {
8358
8358
  return;
8359
8359
  }
8360
8360
  if (layerChangeBtwHeadAndTail && layerChangeAtDistance > 0) {
8361
- const pointBeforeChange = this.getPointAtDistance(layerChangeAtDistance);
8361
+ const indexAfterLayerChange = this.getNearestIndexForDistance(layerChangeAtDistance) + 1;
8362
+ const pointAfterChange = this.inputRoute.route[indexAfterLayerChange];
8363
+ const viaLocation = { x: pointAfterChange.x, y: pointAfterChange.y };
8362
8364
  if (this.lastValidPath) {
8363
8365
  this.addPathToResult(this.lastValidPath);
8364
8366
  this.lastValidPath = null;
8365
8367
  }
8366
- const indexAfterLayerChange = this.getNearestIndexForDistance(layerChangeAtDistance) + 1;
8367
- const pointAfterChange = this.inputRoute.route[indexAfterLayerChange];
8368
- this.newVias.push({
8369
- x: pointAfterChange.x,
8370
- y: pointAfterChange.y
8368
+ const lastPointInNewRoute = this.newRoute[this.newRoute.length - 1];
8369
+ if (lastPointInNewRoute.x !== viaLocation.x || lastPointInNewRoute.y !== viaLocation.y) {
8370
+ this.newRoute.push({
8371
+ x: viaLocation.x,
8372
+ y: viaLocation.y,
8373
+ z: lastPointInNewRoute.z
8374
+ // Use the Z of the layer we are leaving
8375
+ });
8376
+ }
8377
+ this.newVias.push(viaLocation);
8378
+ this.newRoute.push({
8379
+ x: viaLocation.x,
8380
+ y: viaLocation.y,
8381
+ z: pointAfterChange.z
8382
+ // Use the Z of the layer we are entering
8371
8383
  });
8372
- this.newRoute.push(pointAfterChange);
8373
8384
  this.currentStepSize = this.maxStepSize;
8374
- if (this.pathSegments[indexAfterLayerChange]) {
8375
- this.tailDistanceAlongPath = this.pathSegments[indexAfterLayerChange].startDistance;
8385
+ const segmentIndexAfterChange = this.pathSegments.findIndex(
8386
+ (seg) => seg.start === pointAfterChange
8387
+ );
8388
+ if (segmentIndexAfterChange !== -1) {
8389
+ this.tailDistanceAlongPath = this.pathSegments[segmentIndexAfterChange].startDistance;
8376
8390
  this.headDistanceAlongPath = this.tailDistanceAlongPath;
8391
+ this.lastValidPath = null;
8392
+ this.lastValidPathHeadDistance = this.tailDistanceAlongPath;
8393
+ } else if (indexAfterLayerChange < this.inputRoute.route.length) {
8394
+ console.warn(
8395
+ "Fallback used for tailDistanceAlongPath after layer change"
8396
+ );
8397
+ const segment = this.pathSegments.find(
8398
+ (seg) => seg.start === this.inputRoute.route[indexAfterLayerChange]
8399
+ );
8400
+ if (segment) {
8401
+ this.tailDistanceAlongPath = segment.startDistance;
8402
+ this.headDistanceAlongPath = this.tailDistanceAlongPath;
8403
+ this.lastValidPath = null;
8404
+ this.lastValidPathHeadDistance = this.tailDistanceAlongPath;
8405
+ } else {
8406
+ console.error(
8407
+ "Could not find segment start after layer change, path might be incomplete."
8408
+ );
8409
+ this.solved = true;
8410
+ }
8377
8411
  } else {
8378
- console.error("Creating via at end, this is probably not right");
8412
+ console.warn("Layer change occurred at the end of the path.");
8379
8413
  this.solved = true;
8380
- return;
8381
8414
  }
8382
8415
  return;
8383
8416
  }
@@ -8387,8 +8420,17 @@ var SingleSimplifiedPathSolver5 = class extends SingleSimplifiedPathSolver {
8387
8420
  return;
8388
8421
  }
8389
8422
  if (!path45 && !this.lastValidPath) {
8423
+ const oldTailPoint = this.getPointAtDistance(this.tailDistanceAlongPath);
8390
8424
  this.tailDistanceAlongPath += this.minStepSize;
8391
8425
  this.moveHead(this.minStepSize);
8426
+ const newTailIndex = this.getNearestIndexForDistance(
8427
+ this.tailDistanceAlongPath
8428
+ );
8429
+ const newTailPoint = this.inputRoute.route[newTailIndex];
8430
+ const lastRoutePoint = this.inputRoute.route[this.inputRoute.route.length - 1];
8431
+ if (!this.arePointsEqual(oldTailPoint, newTailPoint) && !this.arePointsEqual(newTailPoint, lastRoutePoint)) {
8432
+ this.newRoute.push(newTailPoint);
8433
+ }
8392
8434
  return;
8393
8435
  }
8394
8436
  if (path45) {