@tscircuit/capacity-autorouter 0.0.39 → 0.0.40

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
@@ -5122,47 +5122,72 @@ var UnravelSectionSolver = class extends BaseSolver {
5122
5122
  const Bmutable = this.unravelSection.mutableSegmentIds.has(B.segmentId);
5123
5123
  const Cmutable = this.unravelSection.mutableSegmentIds.has(C.segmentId);
5124
5124
  const Dmutable = this.unravelSection.mutableSegmentIds.has(D.segmentId);
5125
+ const aSegment = this.dedupedSegmentMap.get(A.segmentId);
5126
+ const bSegment = this.dedupedSegmentMap.get(B.segmentId);
5127
+ const cSegment = this.dedupedSegmentMap.get(C.segmentId);
5128
+ const dSegment = this.dedupedSegmentMap.get(D.segmentId);
5129
+ const isNewZAvailableForAll = (segmentObjects, newZ) => {
5130
+ return segmentObjects.every((seg) => seg.availableZ.includes(newZ));
5131
+ };
5125
5132
  if (Amutable && Bmutable) {
5126
- operations.push({
5127
- type: "change_layer",
5128
- newZ: A.z === 0 ? 1 : 0,
5129
- segmentPointIds: [APointId, BPointId]
5130
- });
5133
+ const newZ = A.z === 0 ? 1 : 0;
5134
+ if (isNewZAvailableForAll([aSegment, bSegment], newZ)) {
5135
+ operations.push({
5136
+ type: "change_layer",
5137
+ newZ,
5138
+ segmentPointIds: [APointId, BPointId]
5139
+ });
5140
+ }
5131
5141
  }
5132
5142
  if (Cmutable && Dmutable) {
5133
- operations.push({
5134
- type: "change_layer",
5135
- newZ: C.z === 0 ? 1 : 0,
5136
- segmentPointIds: [CPointId, DPointId]
5137
- });
5143
+ const newZ = C.z === 0 ? 1 : 0;
5144
+ if (isNewZAvailableForAll([cSegment, dSegment], newZ)) {
5145
+ operations.push({
5146
+ type: "change_layer",
5147
+ newZ,
5148
+ segmentPointIds: [CPointId, DPointId]
5149
+ });
5150
+ }
5138
5151
  }
5139
5152
  if (Amutable) {
5140
- operations.push({
5141
- type: "change_layer",
5142
- newZ: A.z === 0 ? 1 : 0,
5143
- segmentPointIds: [APointId]
5144
- });
5153
+ const newZ = A.z === 0 ? 1 : 0;
5154
+ if (aSegment.availableZ.includes(newZ)) {
5155
+ operations.push({
5156
+ type: "change_layer",
5157
+ newZ,
5158
+ segmentPointIds: [APointId]
5159
+ });
5160
+ }
5145
5161
  }
5146
5162
  if (Bmutable) {
5147
- operations.push({
5148
- type: "change_layer",
5149
- newZ: B.z === 0 ? 1 : 0,
5150
- segmentPointIds: [BPointId]
5151
- });
5163
+ const newZ = B.z === 0 ? 1 : 0;
5164
+ if (bSegment.availableZ.includes(newZ)) {
5165
+ operations.push({
5166
+ type: "change_layer",
5167
+ newZ,
5168
+ segmentPointIds: [BPointId]
5169
+ });
5170
+ }
5152
5171
  }
5153
5172
  if (Cmutable) {
5154
- operations.push({
5155
- type: "change_layer",
5156
- newZ: C.z === 0 ? 1 : 0,
5157
- segmentPointIds: [CPointId]
5158
- });
5173
+ const newZ = C.z === 0 ? 1 : 0;
5174
+ if (cSegment.availableZ.includes(newZ)) {
5175
+ operations.push({
5176
+ type: "change_layer",
5177
+ newZ,
5178
+ segmentPointIds: [CPointId]
5179
+ });
5180
+ }
5159
5181
  }
5160
5182
  if (Dmutable) {
5161
- operations.push({
5162
- type: "change_layer",
5163
- newZ: D.z === 0 ? 1 : 0,
5164
- segmentPointIds: [DPointId]
5165
- });
5183
+ const newZ = D.z === 0 ? 1 : 0;
5184
+ if (dSegment.availableZ.includes(newZ)) {
5185
+ operations.push({
5186
+ type: "change_layer",
5187
+ newZ,
5188
+ segmentPointIds: [DPointId]
5189
+ });
5190
+ }
5166
5191
  }
5167
5192
  }
5168
5193
  return operations;
@@ -5851,6 +5876,7 @@ var createRectFromCapacityNode = (node, opts = {}) => {
5851
5876
  "0": "rgba(0,200,200, 0.1)",
5852
5877
  "1": "rgba(0,0,200, 0.1)"
5853
5878
  }[node.availableZ.join(",")] ?? "rgba(0,200,200,0.1)",
5879
+ layer: `z${node.availableZ.join(",")}`,
5854
5880
  label: [
5855
5881
  node.capacityMeshNodeId,
5856
5882
  `availableZ: ${node.availableZ.join(",")}`,
@@ -6040,6 +6066,7 @@ var CapacityPathingSolver = class extends BaseSolver {
6040
6066
  this.currentConnectionIndex++;
6041
6067
  this.candidates = null;
6042
6068
  this.visitedNodes = null;
6069
+ this.failed = true;
6043
6070
  return;
6044
6071
  }
6045
6072
  if (this.isConnectedToEndGoal(currentCandidate.node, end)) {
@@ -6098,11 +6125,14 @@ var CapacityPathingSolver = class extends BaseSolver {
6098
6125
  for (let i = 0; i < this.connectionsWithNodes.length; i++) {
6099
6126
  const conn = this.connectionsWithNodes[i];
6100
6127
  if (conn.path && conn.path.length > 0) {
6101
- const pathPoints = conn.path.map(({ center: { x, y }, width }) => ({
6102
- // slight offset to allow viewing overlapping paths
6103
- x: x + (i % 10 + i % 19) * (5e-3 * width),
6104
- y: y + (i % 10 + i % 19) * (5e-3 * width)
6105
- }));
6128
+ const pathPoints = conn.path.map(
6129
+ ({ center: { x, y }, width, availableZ }) => ({
6130
+ // slight offset to allow viewing overlapping paths
6131
+ x: x + (i % 10 + i % 19) * (5e-3 * width),
6132
+ y: y + (i % 10 + i % 19) * (5e-3 * width),
6133
+ availableZ
6134
+ })
6135
+ );
6106
6136
  graphics.lines.push({
6107
6137
  points: pathPoints,
6108
6138
  strokeColor: this.colorMap[conn.connection.name]
@@ -6114,7 +6144,8 @@ var CapacityPathingSolver = class extends BaseSolver {
6114
6144
  y: point.y,
6115
6145
  label: [
6116
6146
  `conn: ${conn.connection.name}`,
6117
- `node: ${conn.path[u].capacityMeshNodeId}`
6147
+ `node: ${conn.path[u].capacityMeshNodeId}`,
6148
+ `z: ${point.availableZ.join(",")}`
6118
6149
  ].join("\n")
6119
6150
  });
6120
6151
  }
@@ -6201,7 +6232,20 @@ var CapacityPathingSolver5 = class extends CapacityPathingSolver {
6201
6232
  * Penalty you pay for using this node
6202
6233
  */
6203
6234
  getNodeCapacityPenalty(node) {
6204
- return 0.05;
6235
+ const MAX_PENALTY = node.width + node.height;
6236
+ const MIN_PENALTY = 0.05;
6237
+ const START_PENALIZING_CAPACITY_WHEN_IT_DROPS_BELOW = 2;
6238
+ const totalCapacity = this.getTotalCapacity(node);
6239
+ const usedCapacity = this.usedNodeCapacityMap.get(node.capacityMeshNodeId) ?? 0;
6240
+ const remainingCapacity = totalCapacity - usedCapacity;
6241
+ if (remainingCapacity > START_PENALIZING_CAPACITY_WHEN_IT_DROPS_BELOW) {
6242
+ return MIN_PENALTY;
6243
+ }
6244
+ const penalty = (MAX_PENALTY - MIN_PENALTY) * Math.max(
6245
+ 1,
6246
+ (START_PENALIZING_CAPACITY_WHEN_IT_DROPS_BELOW - remainingCapacity) / (MAX_PENALTY - MIN_PENALTY)
6247
+ ) + MIN_PENALTY;
6248
+ return penalty;
6205
6249
  }
6206
6250
  /**
6207
6251
  * We're rewarding travel into big nodes.
@@ -6217,7 +6261,7 @@ var CapacityPathingSolver5 = class extends CapacityPathingSolver {
6217
6261
  return prevCandidate.g + this.getDistanceBetweenNodes(prevCandidate.node, node) + this.getNodeCapacityPenalty(node);
6218
6262
  }
6219
6263
  computeH(prevCandidate, node, endGoal) {
6220
- return this.getDistanceBetweenNodes(node, endGoal);
6264
+ return this.getDistanceBetweenNodes(node, endGoal) + this.getNodeCapacityPenalty(node);
6221
6265
  }
6222
6266
  };
6223
6267
 
@@ -6362,7 +6406,7 @@ var StrawSolver = class extends BaseSolver {
6362
6406
  this.solved = true;
6363
6407
  return;
6364
6408
  }
6365
- if (rootNode.width < this.strawSize * 5 && rootNode.height < this.strawSize * 5) {
6409
+ if (rootNode.width < this.strawSize && rootNode.height < this.strawSize) {
6366
6410
  this.skippedNodes.push(rootNode);
6367
6411
  return;
6368
6412
  }