@tscircuit/capacity-autorouter 0.0.84 → 0.0.86
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 +19 -1
- package/dist/index.js +121 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1732,6 +1732,22 @@ declare class CapacityMeshEdgeSolver2_NodeTreeOptimization extends CapacityMeshE
|
|
|
1732
1732
|
_step(): void;
|
|
1733
1733
|
}
|
|
1734
1734
|
|
|
1735
|
+
declare class DeadEndSolver extends BaseSolver {
|
|
1736
|
+
removedNodeIds: Set<string>;
|
|
1737
|
+
private targetNodeIds;
|
|
1738
|
+
private leaves;
|
|
1739
|
+
private leavesIndex;
|
|
1740
|
+
private adjacencyList;
|
|
1741
|
+
private nodes;
|
|
1742
|
+
private edges;
|
|
1743
|
+
constructor({ nodes, edges, }: {
|
|
1744
|
+
nodes: CapacityMeshNode[];
|
|
1745
|
+
edges: CapacityMeshEdge[];
|
|
1746
|
+
});
|
|
1747
|
+
_step(): void;
|
|
1748
|
+
visualize(): GraphicsObject;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1735
1751
|
interface Point {
|
|
1736
1752
|
x: number;
|
|
1737
1753
|
y: number;
|
|
@@ -1871,6 +1887,7 @@ declare class AutoroutingPipelineSolver extends BaseSolver {
|
|
|
1871
1887
|
highDensityStitchSolver?: MultipleHighDensityRouteStitchSolver;
|
|
1872
1888
|
singleLayerNodeMerger?: SingleLayerNodeMergerSolver;
|
|
1873
1889
|
strawSolver?: StrawSolver;
|
|
1890
|
+
deadEndSolver?: DeadEndSolver;
|
|
1874
1891
|
uselessViaRemovalSolver1?: UselessViaRemovalSolver;
|
|
1875
1892
|
uselessViaRemovalSolver2?: UselessViaRemovalSolver;
|
|
1876
1893
|
multiSimplifiedPathSolver1?: MultiSimplifiedPathSolver;
|
|
@@ -1882,8 +1899,9 @@ declare class AutoroutingPipelineSolver extends BaseSolver {
|
|
|
1882
1899
|
connMap: ConnectivityMap;
|
|
1883
1900
|
srjWithPointPairs?: SimpleRouteJson;
|
|
1884
1901
|
capacityNodes: CapacityMeshNode[] | null;
|
|
1902
|
+
capacityEdges: CapacityMeshEdge[] | null;
|
|
1885
1903
|
cacheProvider: CacheProvider | null;
|
|
1886
|
-
pipelineDef: (PipelineStep<typeof NetToPointPairsSolver> | PipelineStep<typeof CapacityMeshNodeSolver2_NodeUnderObstacle> | PipelineStep<typeof SingleLayerNodeMergerSolver> | PipelineStep<typeof StrawSolver> | PipelineStep<typeof CapacityMeshEdgeSolver2_NodeTreeOptimization> | PipelineStep<typeof CapacityPathingGreedySolver> | PipelineStep<typeof CapacityPathingMultiSectionSolver> | PipelineStep<typeof CapacityEdgeToPortSegmentSolver> | PipelineStep<typeof CapacitySegmentToPointSolver> | PipelineStep<typeof UnravelMultiSectionSolver> | PipelineStep<typeof HighDensitySolver> | PipelineStep<typeof MultipleHighDensityRouteStitchSolver> | PipelineStep<typeof UselessViaRemovalSolver> | PipelineStep<typeof MultiSimplifiedPathSolver>)[];
|
|
1904
|
+
pipelineDef: (PipelineStep<typeof NetToPointPairsSolver> | PipelineStep<typeof CapacityMeshNodeSolver2_NodeUnderObstacle> | PipelineStep<typeof SingleLayerNodeMergerSolver> | PipelineStep<typeof StrawSolver> | PipelineStep<typeof CapacityMeshEdgeSolver2_NodeTreeOptimization> | PipelineStep<typeof DeadEndSolver> | PipelineStep<typeof CapacityPathingGreedySolver> | PipelineStep<typeof CapacityPathingMultiSectionSolver> | PipelineStep<typeof CapacityEdgeToPortSegmentSolver> | PipelineStep<typeof CapacitySegmentToPointSolver> | PipelineStep<typeof UnravelMultiSectionSolver> | PipelineStep<typeof HighDensitySolver> | PipelineStep<typeof MultipleHighDensityRouteStitchSolver> | PipelineStep<typeof UselessViaRemovalSolver> | PipelineStep<typeof MultiSimplifiedPathSolver>)[];
|
|
1887
1905
|
constructor(srj: SimpleRouteJson, opts?: CapacityMeshSolverOptions);
|
|
1888
1906
|
currentPipelineStepIndex: number;
|
|
1889
1907
|
_step(): void;
|
package/dist/index.js
CHANGED
|
@@ -11433,6 +11433,9 @@ peg$SyntaxError.buildMessage = function(expected, found) {
|
|
|
11433
11433
|
var approximateCoordinate = (coord) => {
|
|
11434
11434
|
return (Math.round(coord * 20) / 20).toFixed(2);
|
|
11435
11435
|
};
|
|
11436
|
+
var approximateDeltaCoordinate = (coord) => {
|
|
11437
|
+
return (Math.round(coord * 1e3) / 1e3).toFixed(3);
|
|
11438
|
+
};
|
|
11436
11439
|
setupGlobalCaches();
|
|
11437
11440
|
var CachedUnravelSectionSolver = class extends UnravelSectionSolver {
|
|
11438
11441
|
cacheHit = false;
|
|
@@ -11696,7 +11699,7 @@ var CachedUnravelSectionSolver = class extends UnravelSectionSolver {
|
|
|
11696
11699
|
let hasDelta = false;
|
|
11697
11700
|
if (modifiedPoint.x !== void 0) {
|
|
11698
11701
|
const dx = modifiedPoint.x - originalSegmentPoint.x;
|
|
11699
|
-
const approxDx =
|
|
11702
|
+
const approxDx = approximateDeltaCoordinate(dx);
|
|
11700
11703
|
if (parseFloat(approxDx) !== 0) {
|
|
11701
11704
|
normDelta.dx = approxDx;
|
|
11702
11705
|
hasDelta = true;
|
|
@@ -11704,7 +11707,7 @@ var CachedUnravelSectionSolver = class extends UnravelSectionSolver {
|
|
|
11704
11707
|
}
|
|
11705
11708
|
if (modifiedPoint.y !== void 0) {
|
|
11706
11709
|
const dy = modifiedPoint.y - originalSegmentPoint.y;
|
|
11707
|
-
const approxDy =
|
|
11710
|
+
const approxDy = approximateDeltaCoordinate(dy);
|
|
11708
11711
|
if (parseFloat(approxDy) !== 0) {
|
|
11709
11712
|
normDelta.dy = approxDy;
|
|
11710
11713
|
hasDelta = true;
|
|
@@ -15798,6 +15801,93 @@ var CapacityMeshEdgeSolver2_NodeTreeOptimization = class extends CapacityMeshEdg
|
|
|
15798
15801
|
}
|
|
15799
15802
|
};
|
|
15800
15803
|
|
|
15804
|
+
// lib/solvers/DeadEndSolver/DeadEndSolver.ts
|
|
15805
|
+
var DeadEndSolver = class extends BaseSolver {
|
|
15806
|
+
removedNodeIds;
|
|
15807
|
+
targetNodeIds;
|
|
15808
|
+
leaves;
|
|
15809
|
+
leavesIndex;
|
|
15810
|
+
adjacencyList;
|
|
15811
|
+
// Store the nodes and edges just for visualization purposes
|
|
15812
|
+
nodes;
|
|
15813
|
+
edges;
|
|
15814
|
+
constructor({
|
|
15815
|
+
nodes,
|
|
15816
|
+
edges
|
|
15817
|
+
}) {
|
|
15818
|
+
super();
|
|
15819
|
+
this.MAX_ITERATIONS = nodes.length;
|
|
15820
|
+
this.nodes = nodes;
|
|
15821
|
+
this.edges = edges;
|
|
15822
|
+
this.removedNodeIds = /* @__PURE__ */ new Set();
|
|
15823
|
+
this.targetNodeIds = new Set(
|
|
15824
|
+
nodes.filter((n) => n._containsTarget).map((n) => n.capacityMeshNodeId)
|
|
15825
|
+
);
|
|
15826
|
+
this.adjacencyList = new Map(
|
|
15827
|
+
nodes.map(({ capacityMeshNodeId }) => [capacityMeshNodeId, /* @__PURE__ */ new Set()])
|
|
15828
|
+
);
|
|
15829
|
+
for (const {
|
|
15830
|
+
nodeIds: [u, v]
|
|
15831
|
+
} of edges) {
|
|
15832
|
+
this.adjacencyList.get(u).add(v);
|
|
15833
|
+
this.adjacencyList.get(v).add(u);
|
|
15834
|
+
}
|
|
15835
|
+
this.leavesIndex = 0;
|
|
15836
|
+
this.leaves = [...this.adjacencyList.entries()].filter(([_, neighbours]) => neighbours.size === 1).filter(([nodeId, _]) => !this.targetNodeIds.has(nodeId)).map(([nodeId, _]) => nodeId);
|
|
15837
|
+
}
|
|
15838
|
+
_step() {
|
|
15839
|
+
if (this.leavesIndex === this.leaves.length) {
|
|
15840
|
+
this.solved = true;
|
|
15841
|
+
return;
|
|
15842
|
+
}
|
|
15843
|
+
const leaf = this.leaves[this.leavesIndex];
|
|
15844
|
+
const [neighbor] = this.adjacencyList.get(leaf);
|
|
15845
|
+
const neighborsOfLeafNeighbor = this.adjacencyList.get(neighbor);
|
|
15846
|
+
neighborsOfLeafNeighbor.delete(leaf);
|
|
15847
|
+
this.removedNodeIds.add(leaf);
|
|
15848
|
+
if (neighborsOfLeafNeighbor.size === 1 && !this.targetNodeIds.has(neighbor)) {
|
|
15849
|
+
this.leaves.push(neighbor);
|
|
15850
|
+
}
|
|
15851
|
+
this.leavesIndex += 1;
|
|
15852
|
+
if (this.leavesIndex === this.leaves.length) {
|
|
15853
|
+
this.solved = true;
|
|
15854
|
+
}
|
|
15855
|
+
}
|
|
15856
|
+
visualize() {
|
|
15857
|
+
const graphics = {
|
|
15858
|
+
lines: [],
|
|
15859
|
+
points: [],
|
|
15860
|
+
rects: [],
|
|
15861
|
+
circles: []
|
|
15862
|
+
};
|
|
15863
|
+
for (const edge of this.edges) {
|
|
15864
|
+
if (!edge.nodeIds.some((nodeId) => this.removedNodeIds.has(nodeId))) {
|
|
15865
|
+
continue;
|
|
15866
|
+
}
|
|
15867
|
+
const [node1, node2] = edge.nodeIds.map((nodeId) => {
|
|
15868
|
+
return this.nodes.find((node) => node.capacityMeshNodeId === nodeId);
|
|
15869
|
+
});
|
|
15870
|
+
if (node1?.center && node2?.center) {
|
|
15871
|
+
const lowestZ1 = Math.min(...node1.availableZ);
|
|
15872
|
+
const lowestZ2 = Math.min(...node2.availableZ);
|
|
15873
|
+
const nodeCenter1Adj = {
|
|
15874
|
+
x: node1.center.x + lowestZ1 * node1.width * 0.05,
|
|
15875
|
+
y: node1.center.y - lowestZ1 * node1.width * 0.05
|
|
15876
|
+
};
|
|
15877
|
+
const nodeCenter2Adj = {
|
|
15878
|
+
x: node2.center.x + lowestZ2 * node2.width * 0.05,
|
|
15879
|
+
y: node2.center.y - lowestZ2 * node2.width * 0.05
|
|
15880
|
+
};
|
|
15881
|
+
graphics.lines.push({
|
|
15882
|
+
strokeColor: "black",
|
|
15883
|
+
points: [nodeCenter1Adj, nodeCenter2Adj]
|
|
15884
|
+
});
|
|
15885
|
+
}
|
|
15886
|
+
}
|
|
15887
|
+
return graphics;
|
|
15888
|
+
}
|
|
15889
|
+
};
|
|
15890
|
+
|
|
15801
15891
|
// lib/data-structures/HighDensityRouteSpatialIndex.ts
|
|
15802
15892
|
var getSegmentBounds2 = (segment) => {
|
|
15803
15893
|
return {
|
|
@@ -16406,6 +16496,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16406
16496
|
highDensityStitchSolver;
|
|
16407
16497
|
singleLayerNodeMerger;
|
|
16408
16498
|
strawSolver;
|
|
16499
|
+
deadEndSolver;
|
|
16409
16500
|
uselessViaRemovalSolver1;
|
|
16410
16501
|
uselessViaRemovalSolver2;
|
|
16411
16502
|
multiSimplifiedPathSolver1;
|
|
@@ -16417,6 +16508,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16417
16508
|
connMap;
|
|
16418
16509
|
srjWithPointPairs;
|
|
16419
16510
|
capacityNodes = null;
|
|
16511
|
+
capacityEdges = null;
|
|
16420
16512
|
cacheProvider = null;
|
|
16421
16513
|
pipelineDef = [
|
|
16422
16514
|
definePipelineStep(
|
|
@@ -16481,7 +16573,28 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16481
16573
|
definePipelineStep(
|
|
16482
16574
|
"edgeSolver",
|
|
16483
16575
|
CapacityMeshEdgeSolver2_NodeTreeOptimization,
|
|
16484
|
-
(cms) => [cms.capacityNodes]
|
|
16576
|
+
(cms) => [cms.capacityNodes],
|
|
16577
|
+
{
|
|
16578
|
+
onSolved: (cms) => {
|
|
16579
|
+
cms.capacityEdges = cms.edgeSolver?.edges;
|
|
16580
|
+
}
|
|
16581
|
+
}
|
|
16582
|
+
),
|
|
16583
|
+
definePipelineStep(
|
|
16584
|
+
"deadEndSolver",
|
|
16585
|
+
DeadEndSolver,
|
|
16586
|
+
(cms) => [{ nodes: cms.capacityNodes, edges: cms.capacityEdges }],
|
|
16587
|
+
{
|
|
16588
|
+
onSolved: (cms) => {
|
|
16589
|
+
const removedNodeIds = cms.deadEndSolver?.removedNodeIds;
|
|
16590
|
+
cms.capacityNodes = cms.capacityNodes.filter(
|
|
16591
|
+
(n) => !removedNodeIds.has(n.capacityMeshNodeId)
|
|
16592
|
+
);
|
|
16593
|
+
cms.capacityEdges = cms.capacityEdges.filter(
|
|
16594
|
+
(e) => e.nodeIds.every((nodeId) => !removedNodeIds.has(nodeId))
|
|
16595
|
+
);
|
|
16596
|
+
}
|
|
16597
|
+
}
|
|
16485
16598
|
),
|
|
16486
16599
|
definePipelineStep(
|
|
16487
16600
|
"initialPathingSolver",
|
|
@@ -16490,7 +16603,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16490
16603
|
{
|
|
16491
16604
|
simpleRouteJson: cms.srjWithPointPairs,
|
|
16492
16605
|
nodes: cms.capacityNodes,
|
|
16493
|
-
edges: cms.
|
|
16606
|
+
edges: cms.capacityEdges || [],
|
|
16494
16607
|
colorMap: cms.colorMap,
|
|
16495
16608
|
hyperParameters: {
|
|
16496
16609
|
MAX_CAPACITY_FACTOR: 1
|
|
@@ -16508,7 +16621,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16508
16621
|
initialPathingSolver: cms.initialPathingSolver,
|
|
16509
16622
|
simpleRouteJson: cms.srjWithPointPairs,
|
|
16510
16623
|
nodes: cms.capacityNodes,
|
|
16511
|
-
edges: cms.
|
|
16624
|
+
edges: cms.capacityEdges || [],
|
|
16512
16625
|
colorMap: cms.colorMap,
|
|
16513
16626
|
cacheProvider: cms.cacheProvider,
|
|
16514
16627
|
hyperParameters: {
|
|
@@ -16523,7 +16636,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16523
16636
|
(cms) => [
|
|
16524
16637
|
{
|
|
16525
16638
|
nodes: cms.capacityNodes,
|
|
16526
|
-
edges: cms.
|
|
16639
|
+
edges: cms.capacityEdges || [],
|
|
16527
16640
|
capacityPaths: cms.pathingOptimizer?.getCapacityPaths() || [],
|
|
16528
16641
|
colorMap: cms.colorMap
|
|
16529
16642
|
}
|
|
@@ -16684,6 +16797,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16684
16797
|
const singleLayerNodeMergerViz = this.singleLayerNodeMerger?.visualize();
|
|
16685
16798
|
const strawSolverViz = this.strawSolver?.visualize();
|
|
16686
16799
|
const edgeViz = this.edgeSolver?.visualize();
|
|
16800
|
+
const deadEndViz = this.deadEndSolver?.visualize();
|
|
16687
16801
|
const initialPathingViz = this.initialPathingSolver?.visualize();
|
|
16688
16802
|
const pathingOptimizerViz = this.pathingOptimizer?.visualize();
|
|
16689
16803
|
const edgeToPortSegmentViz = this.edgeToPortSegmentSolver?.visualize();
|
|
@@ -16740,6 +16854,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16740
16854
|
singleLayerNodeMergerViz,
|
|
16741
16855
|
strawSolverViz,
|
|
16742
16856
|
edgeViz,
|
|
16857
|
+
deadEndViz,
|
|
16743
16858
|
initialPathingViz,
|
|
16744
16859
|
pathingOptimizerViz,
|
|
16745
16860
|
edgeToPortSegmentViz,
|