@crazyhappyone/auto-graph 0.2.0 → 0.2.1
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/cli/index.cjs +44 -16
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +44 -16
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +44 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3984,15 +3984,25 @@ function isValidDimension(value) {
|
|
|
3984
3984
|
}
|
|
3985
3985
|
|
|
3986
3986
|
// src/routing/astar.ts
|
|
3987
|
-
function findObstacleFreePath(source, target, obstacles, options = {}) {
|
|
3987
|
+
function findObstacleFreePath(source, target, obstacles, options = {}, diagnostics) {
|
|
3988
3988
|
const margin = options.margin ?? 0;
|
|
3989
3989
|
const turnPenalty = options.turnPenalty ?? 50;
|
|
3990
3990
|
const segmentPenalty = options.segmentPenalty ?? 1;
|
|
3991
3991
|
const endpointObstacles = options.endpointObstacles ?? [];
|
|
3992
|
-
const maxNodes = options.maxNodes ?? 4e3;
|
|
3992
|
+
const maxNodes = options.maxNodes ?? (obstacles.length > 30 ? 16e3 : 4e3);
|
|
3993
3993
|
const xs = collectXs(source, target, obstacles, margin);
|
|
3994
3994
|
const ys = collectYs(source, target, obstacles, margin);
|
|
3995
3995
|
if (xs.length * ys.length > maxNodes) {
|
|
3996
|
+
diagnostics?.push({
|
|
3997
|
+
severity: "warning",
|
|
3998
|
+
code: "routing.astar.grid_overflow",
|
|
3999
|
+
message: `A* grid overflow: ${xs.length * ys.length} nodes > ${maxNodes} limit. Falling back to heuristic routing.`,
|
|
4000
|
+
detail: {
|
|
4001
|
+
xsCount: xs.length,
|
|
4002
|
+
ysCount: ys.length,
|
|
4003
|
+
maxNodes
|
|
4004
|
+
}
|
|
4005
|
+
});
|
|
3996
4006
|
return null;
|
|
3997
4007
|
}
|
|
3998
4008
|
const { nodes, nodeIndex } = buildGraph(xs, ys);
|
|
@@ -4010,24 +4020,41 @@ function findObstacleFreePath(source, target, obstacles, options = {}) {
|
|
|
4010
4020
|
return simplifyRoute(path);
|
|
4011
4021
|
}
|
|
4012
4022
|
function collectXs(source, target, obstacles, margin) {
|
|
4013
|
-
const
|
|
4014
|
-
set.add(source.x);
|
|
4015
|
-
set.add(target.x);
|
|
4023
|
+
const raw = [];
|
|
4016
4024
|
for (const obs of obstacles) {
|
|
4017
|
-
|
|
4018
|
-
set.add(obs.x + obs.width + margin + 2);
|
|
4025
|
+
raw.push(obs.x - margin - 2, obs.x + obs.width + margin + 2);
|
|
4019
4026
|
}
|
|
4020
|
-
|
|
4027
|
+
const deduped = dedupSorted(raw);
|
|
4028
|
+
for (const v of [source.x, target.x]) {
|
|
4029
|
+
if (!deduped.includes(v)) {
|
|
4030
|
+
deduped.push(v);
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
return deduped.sort((a, b) => a - b);
|
|
4021
4034
|
}
|
|
4022
4035
|
function collectYs(source, target, obstacles, margin) {
|
|
4023
|
-
const
|
|
4024
|
-
set.add(source.y);
|
|
4025
|
-
set.add(target.y);
|
|
4036
|
+
const raw = [];
|
|
4026
4037
|
for (const obs of obstacles) {
|
|
4027
|
-
|
|
4028
|
-
|
|
4038
|
+
raw.push(obs.y - margin - 2, obs.y + obs.height + margin + 2);
|
|
4039
|
+
}
|
|
4040
|
+
const deduped = dedupSorted(raw);
|
|
4041
|
+
for (const v of [source.y, target.y]) {
|
|
4042
|
+
if (!deduped.includes(v)) {
|
|
4043
|
+
deduped.push(v);
|
|
4044
|
+
}
|
|
4029
4045
|
}
|
|
4030
|
-
return
|
|
4046
|
+
return deduped.sort((a, b) => a - b);
|
|
4047
|
+
}
|
|
4048
|
+
function dedupSorted(values) {
|
|
4049
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
4050
|
+
const result = [];
|
|
4051
|
+
for (const v of sorted) {
|
|
4052
|
+
const last = result[result.length - 1];
|
|
4053
|
+
if (last === void 0 || v - last > 2) {
|
|
4054
|
+
result.push(v);
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
return result;
|
|
4031
4058
|
}
|
|
4032
4059
|
function buildGraph(xs, ys) {
|
|
4033
4060
|
const nodes = [];
|
|
@@ -4257,7 +4284,8 @@ function routeEdge(input) {
|
|
|
4257
4284
|
[...softObstacles, ...hardObstacles],
|
|
4258
4285
|
{
|
|
4259
4286
|
endpointObstacles
|
|
4260
|
-
}
|
|
4287
|
+
},
|
|
4288
|
+
diagnostics
|
|
4261
4289
|
);
|
|
4262
4290
|
if (path !== null && path.length >= 2) {
|
|
4263
4291
|
const finalized = finalizeRoute(
|
|
@@ -5108,7 +5136,7 @@ function solveDiagram(diagram, options = {}) {
|
|
|
5108
5136
|
direction: diagram.direction,
|
|
5109
5137
|
overlapSpacing: options?.overlapSpacing ?? 40,
|
|
5110
5138
|
...options.minSiblingGap === void 0 ? {} : { minSiblingGap: options.minSiblingGap },
|
|
5111
|
-
|
|
5139
|
+
distributeContainedChildren: options.distributeContainedChildren ?? true,
|
|
5112
5140
|
boxes: initialNodeBoxes,
|
|
5113
5141
|
nodes: styledNodes,
|
|
5114
5142
|
constraints
|