@tscircuit/capacity-autorouter 0.0.33 → 0.0.35
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 +28 -8
- package/dist/index.js +97 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -465,13 +465,6 @@ interface HighDensityHyperParameters {
|
|
|
465
465
|
FLIP_TRACE_ALIGNMENT_DIRECTION: boolean;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
type FutureConnection = {
|
|
469
|
-
connectionName: string;
|
|
470
|
-
points: {
|
|
471
|
-
x: number;
|
|
472
|
-
y: number;
|
|
473
|
-
}[];
|
|
474
|
-
};
|
|
475
468
|
type Node = {
|
|
476
469
|
x: number;
|
|
477
470
|
y: number;
|
|
@@ -481,6 +474,32 @@ type Node = {
|
|
|
481
474
|
f: number;
|
|
482
475
|
parent: Node | null;
|
|
483
476
|
};
|
|
477
|
+
declare class SingleRouteCandidatePriorityQueue {
|
|
478
|
+
private heap;
|
|
479
|
+
constructor(nodes: Node[]);
|
|
480
|
+
private getLeftChildIndex;
|
|
481
|
+
private getRightChildIndex;
|
|
482
|
+
private getParentIndex;
|
|
483
|
+
private hasLeftChild;
|
|
484
|
+
private hasRightChild;
|
|
485
|
+
private hasParent;
|
|
486
|
+
private leftChild;
|
|
487
|
+
private rightChild;
|
|
488
|
+
private parent;
|
|
489
|
+
private swap;
|
|
490
|
+
dequeue(): Node | null;
|
|
491
|
+
enqueue(item: Node): void;
|
|
492
|
+
heapifyUp(): void;
|
|
493
|
+
heapifyDown(): void;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
type FutureConnection = {
|
|
497
|
+
connectionName: string;
|
|
498
|
+
points: {
|
|
499
|
+
x: number;
|
|
500
|
+
y: number;
|
|
501
|
+
}[];
|
|
502
|
+
};
|
|
484
503
|
declare class SingleHighDensityRouteSolver extends BaseSolver {
|
|
485
504
|
obstacleRoutes: HighDensityIntraNodeRoute[];
|
|
486
505
|
bounds: {
|
|
@@ -519,7 +538,7 @@ declare class SingleHighDensityRouteSolver extends BaseSolver {
|
|
|
519
538
|
VIA_PENALTY_FACTOR: number;
|
|
520
539
|
CELL_SIZE_FACTOR: number;
|
|
521
540
|
exploredNodes: Set<string>;
|
|
522
|
-
candidates:
|
|
541
|
+
candidates: SingleRouteCandidatePriorityQueue;
|
|
523
542
|
connectionName: string;
|
|
524
543
|
solvedPath: HighDensityIntraNodeRoute | null;
|
|
525
544
|
futureConnections: FutureConnection[];
|
|
@@ -987,6 +1006,7 @@ declare class SingleHighDensityRouteStitchSolver extends BaseSolver {
|
|
|
987
1006
|
z: number;
|
|
988
1007
|
};
|
|
989
1008
|
constructor(opts: {
|
|
1009
|
+
connectionName?: string;
|
|
990
1010
|
hdRoutes: HighDensityIntraNodeRoute[];
|
|
991
1011
|
start: {
|
|
992
1012
|
x: number;
|
package/dist/index.js
CHANGED
|
@@ -1925,6 +1925,88 @@ function distance(p1, p2) {
|
|
|
1925
1925
|
return Math.sqrt(dx * dx + dy * dy);
|
|
1926
1926
|
}
|
|
1927
1927
|
|
|
1928
|
+
// lib/data-structures/SingleRouteCandidatePriorityQueue.ts
|
|
1929
|
+
var SingleRouteCandidatePriorityQueue = class {
|
|
1930
|
+
heap = [];
|
|
1931
|
+
constructor(nodes) {
|
|
1932
|
+
this.heap = [];
|
|
1933
|
+
for (const node of nodes) {
|
|
1934
|
+
this.enqueue(node);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
getLeftChildIndex(parentIndex) {
|
|
1938
|
+
return 2 * parentIndex + 1;
|
|
1939
|
+
}
|
|
1940
|
+
getRightChildIndex(parentIndex) {
|
|
1941
|
+
return 2 * parentIndex + 2;
|
|
1942
|
+
}
|
|
1943
|
+
getParentIndex(childIndex) {
|
|
1944
|
+
return Math.floor((childIndex - 1) / 2);
|
|
1945
|
+
}
|
|
1946
|
+
hasLeftChild(index) {
|
|
1947
|
+
return this.getLeftChildIndex(index) < this.heap.length;
|
|
1948
|
+
}
|
|
1949
|
+
hasRightChild(index) {
|
|
1950
|
+
return this.getRightChildIndex(index) < this.heap.length;
|
|
1951
|
+
}
|
|
1952
|
+
hasParent(index) {
|
|
1953
|
+
return this.getParentIndex(index) >= 0;
|
|
1954
|
+
}
|
|
1955
|
+
leftChild(index) {
|
|
1956
|
+
return this.heap[this.getLeftChildIndex(index)];
|
|
1957
|
+
}
|
|
1958
|
+
rightChild(index) {
|
|
1959
|
+
return this.heap[this.getRightChildIndex(index)];
|
|
1960
|
+
}
|
|
1961
|
+
parent(index) {
|
|
1962
|
+
return this.heap[this.getParentIndex(index)];
|
|
1963
|
+
}
|
|
1964
|
+
swap(i, j) {
|
|
1965
|
+
const temp = this.heap[i];
|
|
1966
|
+
this.heap[i] = this.heap[j];
|
|
1967
|
+
this.heap[j] = temp;
|
|
1968
|
+
}
|
|
1969
|
+
// Removing an element will remove the
|
|
1970
|
+
// top element with highest priority then
|
|
1971
|
+
// heapifyDown will be called
|
|
1972
|
+
dequeue() {
|
|
1973
|
+
if (this.heap.length === 0) {
|
|
1974
|
+
return null;
|
|
1975
|
+
}
|
|
1976
|
+
const item = this.heap[0];
|
|
1977
|
+
this.heap[0] = this.heap[this.heap.length - 1];
|
|
1978
|
+
this.heap.pop();
|
|
1979
|
+
this.heapifyDown();
|
|
1980
|
+
return item;
|
|
1981
|
+
}
|
|
1982
|
+
enqueue(item) {
|
|
1983
|
+
this.heap.push(item);
|
|
1984
|
+
this.heapifyUp();
|
|
1985
|
+
}
|
|
1986
|
+
heapifyUp() {
|
|
1987
|
+
let index = this.heap.length - 1;
|
|
1988
|
+
while (this.hasParent(index) && this.parent(index).f > this.heap[index].f) {
|
|
1989
|
+
this.swap(this.getParentIndex(index), index);
|
|
1990
|
+
index = this.getParentIndex(index);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
heapifyDown() {
|
|
1994
|
+
let index = 0;
|
|
1995
|
+
while (this.hasLeftChild(index)) {
|
|
1996
|
+
let smallerChildIndex = this.getLeftChildIndex(index);
|
|
1997
|
+
if (this.hasRightChild(index) && this.rightChild(index).f < this.leftChild(index).f) {
|
|
1998
|
+
smallerChildIndex = this.getRightChildIndex(index);
|
|
1999
|
+
}
|
|
2000
|
+
if (this.heap[index].f < this.heap[smallerChildIndex].f) {
|
|
2001
|
+
break;
|
|
2002
|
+
} else {
|
|
2003
|
+
this.swap(index, smallerChildIndex);
|
|
2004
|
+
}
|
|
2005
|
+
index = smallerChildIndex;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
|
|
1928
2010
|
// lib/solvers/HighDensitySolver/SingleHighDensityRouteSolver.ts
|
|
1929
2011
|
var SingleHighDensityRouteSolver = class extends BaseSolver {
|
|
1930
2012
|
obstacleRoutes;
|
|
@@ -1979,7 +2061,7 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
|
|
|
1979
2061
|
this.obstacleMargin = opts.obstacleMargin ?? 0.2;
|
|
1980
2062
|
this.layerCount = opts.layerCount ?? 2;
|
|
1981
2063
|
this.exploredNodes = /* @__PURE__ */ new Set();
|
|
1982
|
-
this.candidates = [
|
|
2064
|
+
this.candidates = new SingleRouteCandidatePriorityQueue([
|
|
1983
2065
|
{
|
|
1984
2066
|
...opts.A,
|
|
1985
2067
|
z: opts.A.z ?? 0,
|
|
@@ -1988,7 +2070,7 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
|
|
|
1988
2070
|
f: 0,
|
|
1989
2071
|
parent: null
|
|
1990
2072
|
}
|
|
1991
|
-
];
|
|
2073
|
+
]);
|
|
1992
2074
|
this.straightLineDistance = distance(this.A, this.B);
|
|
1993
2075
|
this.futureConnections = opts.futureConnections ?? [];
|
|
1994
2076
|
this.MAX_ITERATIONS = 5e3;
|
|
@@ -2208,17 +2290,18 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
|
|
|
2208
2290
|
);
|
|
2209
2291
|
}
|
|
2210
2292
|
_step() {
|
|
2211
|
-
this.candidates.
|
|
2212
|
-
let
|
|
2213
|
-
while (currentNode && this.exploredNodes.has(
|
|
2214
|
-
currentNode = this.candidates.
|
|
2293
|
+
let currentNode = this.candidates.dequeue();
|
|
2294
|
+
let currentNodeKey = currentNode ? this.getNodeKey(currentNode) : void 0;
|
|
2295
|
+
while (currentNode && currentNodeKey && this.exploredNodes.has(currentNodeKey)) {
|
|
2296
|
+
currentNode = this.candidates.dequeue();
|
|
2297
|
+
currentNodeKey = currentNode ? this.getNodeKey(currentNode) : void 0;
|
|
2215
2298
|
}
|
|
2216
|
-
if (!currentNode) {
|
|
2299
|
+
if (!currentNode || !currentNodeKey) {
|
|
2217
2300
|
this.failed = true;
|
|
2218
2301
|
return;
|
|
2219
2302
|
}
|
|
2220
|
-
this.exploredNodes.add(
|
|
2221
|
-
this.debug_exploredNodesOrdered.push(
|
|
2303
|
+
this.exploredNodes.add(currentNodeKey);
|
|
2304
|
+
this.debug_exploredNodesOrdered.push(currentNodeKey);
|
|
2222
2305
|
const goalDist = distance(currentNode, this.B);
|
|
2223
2306
|
this.progress = this.computeProgress(
|
|
2224
2307
|
currentNode,
|
|
@@ -2231,7 +2314,7 @@ var SingleHighDensityRouteSolver = class extends BaseSolver {
|
|
|
2231
2314
|
}
|
|
2232
2315
|
const neighbors = this.getNeighbors(currentNode);
|
|
2233
2316
|
for (const neighbor of neighbors) {
|
|
2234
|
-
this.candidates.
|
|
2317
|
+
this.candidates.enqueue(neighbor);
|
|
2235
2318
|
}
|
|
2236
2319
|
}
|
|
2237
2320
|
visualize() {
|
|
@@ -4213,7 +4296,7 @@ var SingleHighDensityRouteStitchSolver = class extends BaseSolver {
|
|
|
4213
4296
|
super();
|
|
4214
4297
|
this.remainingHdRoutes = [...opts.hdRoutes];
|
|
4215
4298
|
this.mergedHdRoute = {
|
|
4216
|
-
connectionName: opts.hdRoutes[0].connectionName,
|
|
4299
|
+
connectionName: opts.connectionName ?? opts.hdRoutes[0].connectionName,
|
|
4217
4300
|
route: [
|
|
4218
4301
|
{
|
|
4219
4302
|
x: opts.start.x,
|
|
@@ -4222,8 +4305,8 @@ var SingleHighDensityRouteStitchSolver = class extends BaseSolver {
|
|
|
4222
4305
|
}
|
|
4223
4306
|
],
|
|
4224
4307
|
vias: [],
|
|
4225
|
-
viaDiameter: opts.hdRoutes[0].
|
|
4226
|
-
traceThickness: opts.hdRoutes[0].
|
|
4308
|
+
viaDiameter: opts.hdRoutes?.[0]?.viaDiameter ?? 0.6,
|
|
4309
|
+
traceThickness: opts.hdRoutes?.[0]?.traceThickness ?? 0.15
|
|
4227
4310
|
};
|
|
4228
4311
|
this.start = opts.start;
|
|
4229
4312
|
this.end = opts.end;
|
|
@@ -4382,11 +4465,8 @@ var MultipleHighDensityRouteStitchSolver = class extends BaseSolver {
|
|
|
4382
4465
|
this.solved = true;
|
|
4383
4466
|
return;
|
|
4384
4467
|
}
|
|
4385
|
-
if (unsolvedRoute.hdRoutes.length === 0) {
|
|
4386
|
-
console.warn(`No routes to stitch for ${unsolvedRoute.connectionName}`);
|
|
4387
|
-
return;
|
|
4388
|
-
}
|
|
4389
4468
|
this.activeSolver = new SingleHighDensityRouteStitchSolver({
|
|
4469
|
+
connectionName: unsolvedRoute.connectionName,
|
|
4390
4470
|
hdRoutes: unsolvedRoute.hdRoutes,
|
|
4391
4471
|
start: unsolvedRoute.start,
|
|
4392
4472
|
end: unsolvedRoute.end
|