@sentropic/diagram-canvas 0.3.1 → 0.4.0

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.
Files changed (53) hide show
  1. package/README.md +23 -2
  2. package/dist/camera.d.ts +28 -9
  3. package/dist/camera.js +34 -13
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.js +4 -0
  6. package/dist/layout/cache.js +12 -2
  7. package/dist/layout/channels.d.ts +10 -0
  8. package/dist/layout/channels.js +13 -0
  9. package/dist/layout/conventions.d.ts +117 -0
  10. package/dist/layout/conventions.js +185 -0
  11. package/dist/layout/dock.d.ts +2 -0
  12. package/dist/layout/dock.js +5 -1
  13. package/dist/layout/fingerprint.d.ts +4 -2
  14. package/dist/layout/fingerprint.js +26 -2
  15. package/dist/layout/hints.d.ts +1 -1
  16. package/dist/layout/hints.js +10 -3
  17. package/dist/layout/index.d.ts +5 -3
  18. package/dist/layout/index.js +5 -3
  19. package/dist/layout/labels.d.ts +2 -0
  20. package/dist/layout/labels.js +2 -0
  21. package/dist/layout/measure.d.ts +6 -0
  22. package/dist/layout/measure.js +28 -0
  23. package/dist/layout/measured.js +1051 -100
  24. package/dist/layout/route.d.ts +27 -1
  25. package/dist/layout/route.js +640 -32
  26. package/dist/layout/routeSpacing.d.ts +84 -0
  27. package/dist/layout/routeSpacing.js +472 -0
  28. package/dist/layout/spacing.generated.d.ts +10 -1
  29. package/dist/layout/spacing.generated.js +10 -1
  30. package/dist/layout/types.d.ts +33 -2
  31. package/dist/layout/types.js +2 -0
  32. package/dist/presentation/connectorPath.d.ts +32 -0
  33. package/dist/presentation/connectorPath.js +213 -0
  34. package/dist/presentation/connectorStyle.d.ts +70 -0
  35. package/dist/presentation/connectorStyle.js +99 -0
  36. package/dist/presentation/diagramCardModel.d.ts +1 -1
  37. package/dist/presentation/diagramCardModel.js +1 -1
  38. package/dist/presentation/diagramSceneModel.d.ts +58 -7
  39. package/dist/presentation/diagramSceneModel.js +225 -35
  40. package/dist/presentation/diagramSceneTypes.d.ts +9 -0
  41. package/dist/presentation/index.d.ts +4 -0
  42. package/dist/presentation/index.js +4 -0
  43. package/dist/presentation/linkLegend.d.ts +132 -0
  44. package/dist/presentation/linkLegend.js +231 -0
  45. package/dist/presentation/renderSceneSvg.d.ts +3 -1
  46. package/dist/presentation/renderSceneSvg.js +81 -11
  47. package/dist/presentation/sceneLabelClearance.d.ts +1 -1
  48. package/dist/presentation/sceneLabelClearance.js +19 -3
  49. package/dist/r7Mode.d.ts +13 -0
  50. package/dist/r7Mode.js +67 -0
  51. package/dist/visibility.d.ts +1 -1
  52. package/dist/visibility.js +3 -2
  53. package/package.json +2 -2
@@ -3,20 +3,49 @@ import { permuteFlowRuns } from "./flow-order.js";
3
3
  export function routesConflict(left, right) {
4
4
  return fullSharesSegment(left, right) || left.slice(1).some((point, i) => right.slice(1).some((other, j) => segmentsCrossTransversal(left[i], point, right[j], other)));
5
5
  }
6
+ const SPACING_EPS = 1e-4;
7
+ /**
8
+ * Subdivide a clear corridor `[low, high]` (between two consecutive grown
9
+ * boundaries) into parallel routing tracks spaced by at least `routeSpacing`.
10
+ * Always deterministic and symmetric around the corridor midpoint.
11
+ */
12
+ export function subdivideChannelTracks(low, high, routeSpacing) {
13
+ const span = high - low;
14
+ if (!(span >= 0) || !Number.isFinite(span))
15
+ return [];
16
+ const mid = (low + high) / 2;
17
+ if (!(routeSpacing > 0) || !Number.isFinite(routeSpacing) || span < routeSpacing - SPACING_EPS) {
18
+ return [mid];
19
+ }
20
+ const count = Math.min(16, Math.floor((span + SPACING_EPS) / routeSpacing) + 1);
21
+ if (count <= 1)
22
+ return [mid];
23
+ const tracks = [];
24
+ for (let k = 0; k < count; k += 1) {
25
+ tracks.push(mid + (k - (count - 1) / 2) * routeSpacing);
26
+ }
27
+ return tracks;
28
+ }
6
29
  /**
7
30
  * BF-6: try horizontal label channels without changing any box or gutter.
8
31
  * Dock joins keep their outward normals. Every full candidate is checked
9
- * against raw obstacles, containment and the other routes of its pair.
32
+ * against raw obstacles, containment, same-pair bans and optional minimum
33
+ * route spacing / border clearance.
10
34
  */
11
35
  export function labelDetour(input) {
12
36
  const { request, shapes, earlier } = input;
13
- const step = 2;
37
+ const step = input.step ?? 2;
38
+ const routeSpacing = input.routeSpacing ?? 0;
39
+ const borderClearance = input.borderClearance ?? 0;
40
+ const allFixed = input.allFixed ?? [];
41
+ const passableZones = input.passableZones ?? [];
14
42
  const s = { x: request.start.x + step * request.startExit.x, y: request.start.y + step * request.startExit.y };
15
43
  const t = { x: request.end.x + step * request.endExit.x, y: request.end.y + step * request.endExit.y };
16
44
  const clear = (points) => {
17
45
  const within = request.within;
18
46
  if (within !== undefined && points.some((p) => p.x < within.x || p.x > within.x + within.width || p.y < within.y || p.y > within.y + within.height))
19
47
  return false;
48
+ const lastIdx = points.length - 1;
20
49
  for (let i = 1; i < points.length; i += 1) {
21
50
  const a = points[i - 1];
22
51
  const b = points[i];
@@ -24,14 +53,68 @@ export function labelDetour(input) {
24
53
  ? a.y > r.y && a.y < r.y + r.height && Math.max(Math.min(a.x, b.x), r.x) < Math.min(Math.max(a.x, b.x), r.x + r.width)
25
54
  : a.x > r.x && a.x < r.x + r.width && Math.max(Math.min(a.y, b.y), r.y) < Math.min(Math.max(a.y, b.y), r.y + r.height)))
26
55
  return false;
56
+ if (borderClearance > 0) {
57
+ const minX = Math.min(a.x, b.x);
58
+ const maxX = Math.max(a.x, b.x);
59
+ const minY = Math.min(a.y, b.y);
60
+ const maxY = Math.max(a.y, b.y);
61
+ const isFirst = i === 1;
62
+ const isLast = i === lastIdx;
63
+ for (const r of shapes) {
64
+ // Endpoint boxes legitimately touch the start/end dock of the first/last leg.
65
+ if (isFirst && pointOnRectBorder(request.start, r))
66
+ continue;
67
+ if (isLast && pointOnRectBorder(request.end, r))
68
+ continue;
69
+ const dx = maxX < r.x ? r.x - maxX : minX > r.x + r.width ? minX - (r.x + r.width) : 0;
70
+ const dy = maxY < r.y ? r.y - maxY : minY > r.y + r.height ? minY - (r.y + r.height) : 0;
71
+ if (Math.hypot(dx, dy) < borderClearance - SPACING_EPS)
72
+ return false;
73
+ }
74
+ for (const z of passableZones) {
75
+ if (isFirst && pointOnRectBorder(request.start, z))
76
+ continue;
77
+ if (isLast && pointOnRectBorder(request.end, z))
78
+ continue;
79
+ if (Math.abs(a.y - b.y) <= SPACING_EPS && Math.abs(a.x - b.x) > SPACING_EPS) {
80
+ const y = (a.y + b.y) / 2;
81
+ const dx = maxX < z.x ? z.x - maxX : minX > z.x + z.width ? minX - (z.x + z.width) : 0;
82
+ if (Math.hypot(dx, Math.abs(y - z.y)) < borderClearance - SPACING_EPS
83
+ || Math.hypot(dx, Math.abs(y - (z.y + z.height))) < borderClearance - SPACING_EPS)
84
+ return false;
85
+ }
86
+ else if (Math.abs(a.x - b.x) <= SPACING_EPS && Math.abs(a.y - b.y) > SPACING_EPS) {
87
+ const x = (a.x + b.x) / 2;
88
+ const dy = maxY < z.y ? z.y - maxY : minY > z.y + z.height ? minY - (z.y + z.height) : 0;
89
+ if (Math.hypot(Math.abs(x - z.x), dy) < borderClearance - SPACING_EPS
90
+ || Math.hypot(Math.abs(x - (z.x + z.width)), dy) < borderClearance - SPACING_EPS)
91
+ return false;
92
+ }
93
+ }
94
+ }
27
95
  if (sharesSamePair(a, b, earlier) || crossesSamePair(a, b, earlier))
28
96
  return false;
97
+ if (routeSpacing > 0 && violatesParallelSpacing(a, b, allFixed, routeSpacing))
98
+ return false;
29
99
  // Reject a folded-back leg or a self intersection after simplification.
30
100
  for (let j = 1; j < i - 1; j += 1) {
31
101
  const c = points[j - 1];
32
102
  const d = points[j];
33
103
  if (fullSharesSegment([a, b], [c, d]) || segmentsCrossTransversal(a, b, c, d))
34
104
  return false;
105
+ if (routeSpacing > 0 && segmentsCloserThan(a, b, c, d, routeSpacing))
106
+ return false;
107
+ }
108
+ }
109
+ if (routeSpacing > 0 && points.length > 2) {
110
+ for (let i = 1; i < points.length - 1; i += 1) {
111
+ const elbow = points[i];
112
+ for (const other of allFixed) {
113
+ for (let k = 1; k < other.length - 1; k += 1) {
114
+ if (Math.hypot(elbow.x - other[k].x, elbow.y - other[k].y) < routeSpacing - SPACING_EPS)
115
+ return false;
116
+ }
117
+ }
35
118
  }
36
119
  }
37
120
  const first = points[1];
@@ -65,6 +148,39 @@ export function labelDetour(input) {
65
148
  const OVERLAP_PENALTY = 2;
66
149
  const DX = [1, 0, -1, 0];
67
150
  const DY = [0, 1, 0, -1];
151
+ function pointOnRectBorder(point, rect) {
152
+ const onX = (Math.abs(point.x - rect.x) <= SPACING_EPS || Math.abs(point.x - (rect.x + rect.width)) <= SPACING_EPS)
153
+ && point.y >= rect.y - SPACING_EPS && point.y <= rect.y + rect.height + SPACING_EPS;
154
+ const onY = (Math.abs(point.y - rect.y) <= SPACING_EPS || Math.abs(point.y - (rect.y + rect.height)) <= SPACING_EPS)
155
+ && point.x >= rect.x - SPACING_EPS && point.x <= rect.x + rect.width + SPACING_EPS;
156
+ return onX || onY;
157
+ }
158
+ function segmentsCloserThan(a1, a2, b1, b2, minSpacing) {
159
+ if (Math.abs(a1.y - a2.y) <= SPACING_EPS && Math.abs(b1.y - b2.y) <= SPACING_EPS) {
160
+ if (Math.abs(a1.y - b1.y) >= minSpacing - SPACING_EPS)
161
+ return false;
162
+ const overlap = Math.min(Math.max(a1.x, a2.x), Math.max(b1.x, b2.x)) - Math.max(Math.min(a1.x, a2.x), Math.min(b1.x, b2.x));
163
+ return overlap > SPACING_EPS;
164
+ }
165
+ if (Math.abs(a1.x - a2.x) <= SPACING_EPS && Math.abs(b1.x - b2.x) <= SPACING_EPS) {
166
+ if (Math.abs(a1.x - b1.x) >= minSpacing - SPACING_EPS)
167
+ return false;
168
+ const overlap = Math.min(Math.max(a1.y, a2.y), Math.max(b1.y, b2.y)) - Math.max(Math.min(a1.y, a2.y), Math.min(b1.y, b2.y));
169
+ return overlap > SPACING_EPS;
170
+ }
171
+ return false;
172
+ }
173
+ function violatesParallelSpacing(a1, a2, routes, minSpacing) {
174
+ if (Math.abs(a1.x - a2.x) <= SPACING_EPS && Math.abs(a1.y - a2.y) <= SPACING_EPS)
175
+ return false;
176
+ for (const route of routes) {
177
+ for (let j = 1; j < route.length; j += 1) {
178
+ if (segmentsCloserThan(a1, a2, route[j - 1], route[j], minSpacing))
179
+ return true;
180
+ }
181
+ }
182
+ return false;
183
+ }
68
184
  /** Two orthogonal full routes share a segment: a collinear overlap of positive length. */
69
185
  function fullSharesSegment(left, right) {
70
186
  for (let i = 1; i < left.length; i += 1) {
@@ -280,32 +396,93 @@ class LexHeap {
280
396
  }
281
397
  export function routeEdges(input) {
282
398
  const { rects, requests, clearance } = input;
399
+ const routeSpacing = input.routeSpacing !== undefined && input.routeSpacing > 0 ? input.routeSpacing : 0;
400
+ const useSpacing = routeSpacing > 0;
401
+ const barrierPad = input.barrierClearance ?? clearance;
283
402
  const entities = [...rects.keys()].sort();
284
- const grow = (id, rect) => ({
403
+ const grow = (id, rect, pad = clearance) => ({
285
404
  id,
286
- left: rect.x - clearance,
287
- right: rect.x + rect.width + clearance,
288
- top: rect.y - clearance,
289
- bottom: rect.y + rect.height + clearance,
405
+ left: rect.x - pad,
406
+ right: rect.x + rect.width + pad,
407
+ top: rect.y - pad,
408
+ bottom: rect.y + rect.height + pad,
290
409
  });
291
410
  const grown = [
292
- ...entities.map((id) => grow(id, rects.get(id))),
411
+ ...entities.map((id) => grow(id, rects.get(id), clearance)),
293
412
  // Synthetic ids: never an entity reference, hence never in `passable`.
294
- ...(input.barriers ?? []).map((rect, index) => grow(`barrier:${String(index)}`, rect)),
413
+ ...(input.barriers ?? []).map((rect, index) => grow(`barrier:${String(index)}`, rect, barrierPad)),
295
414
  ];
296
- const withChannels = (values) => {
415
+ const withChannels = (pairs) => {
416
+ const starts = new Set();
417
+ const ends = new Set();
418
+ const values = [];
419
+ for (const [lo, hi] of pairs) {
420
+ starts.add(lo);
421
+ ends.add(hi);
422
+ values.push(lo, hi);
423
+ }
297
424
  const sorted = [...new Set(values)].sort((a, b) => a - b);
298
- const mids = [];
299
- for (let index = 1; index < sorted.length; index += 1)
300
- mids.push((sorted[index - 1] + sorted[index]) / 2);
301
- return [...sorted, ...mids];
425
+ const tracks = [];
426
+ for (let index = 1; index < sorted.length; index += 1) {
427
+ const low = sorted[index - 1];
428
+ const high = sorted[index];
429
+ const span = high - low;
430
+ if (useSpacing) {
431
+ const isCorridor = ends.has(low) && starts.has(high);
432
+ if (isCorridor && span <= 300) {
433
+ tracks.push(...subdivideChannelTracks(low, high, routeSpacing));
434
+ }
435
+ else {
436
+ tracks.push((low + high) / 2);
437
+ if (isCorridor) {
438
+ if (low + routeSpacing < high - routeSpacing) {
439
+ tracks.push(low + routeSpacing, high - routeSpacing);
440
+ }
441
+ }
442
+ }
443
+ }
444
+ else {
445
+ tracks.push((low + high) / 2);
446
+ }
447
+ }
448
+ return [...sorted, ...tracks];
302
449
  };
303
450
  const clearancePoint = (point, exit) => ({
304
451
  x: point.x + exit.x * clearance,
305
452
  y: point.y + exit.y * clearance,
306
453
  });
307
- const xValues = withChannels(grown.flatMap((box) => [box.left, box.right]));
308
- const yValues = withChannels(grown.flatMap((box) => [box.top, box.bottom]));
454
+ const xValues = withChannels(grown.map((box) => [box.left, box.right]));
455
+ const yValues = withChannels(grown.map((box) => [box.top, box.bottom]));
456
+ // When spacing is active, add outer perimeter tracks spaced by `routeSpacing`
457
+ // around the drawing so routes overflowing an interior channel can detour cleanly,
458
+ // plus inner clearance lines for passable ancestor zones.
459
+ if (useSpacing && rects.size > 0) {
460
+ const passableIds = new Set();
461
+ for (const req of requests)
462
+ for (const id of req.passable)
463
+ passableIds.add(id);
464
+ for (const id of passableIds) {
465
+ const r = rects.get(id);
466
+ if (r === undefined)
467
+ continue;
468
+ if (r.width > 2 * clearance)
469
+ xValues.push(r.x + clearance, r.x + r.width - clearance);
470
+ if (r.height > 2 * clearance)
471
+ yValues.push(r.y + clearance, r.y + r.height - clearance);
472
+ }
473
+ if (requests.length > 1) {
474
+ const rawList = [...rects.values()];
475
+ const minX = Math.min(...rawList.map((r) => r.x)) - clearance;
476
+ const maxX = Math.max(...rawList.map((r) => r.x + r.width)) + clearance;
477
+ const minY = Math.min(...rawList.map((r) => r.y)) - clearance;
478
+ const maxY = Math.max(...rawList.map((r) => r.y + r.height)) + clearance;
479
+ const perimeterTracks = Math.min(Math.max(4, Math.ceil(requests.length / 3)), 6);
480
+ for (let k = 1; k <= perimeterTracks; k += 1) {
481
+ xValues.push(minX - k * routeSpacing, maxX + k * routeSpacing);
482
+ yValues.push(minY - k * routeSpacing, maxY + k * routeSpacing);
483
+ }
484
+ }
485
+ }
309
486
  for (const request of requests) {
310
487
  for (const point of [clearancePoint(request.start, request.startExit), clearancePoint(request.end, request.endExit)]) {
311
488
  xValues.push(point.x);
@@ -442,6 +619,27 @@ export function routeEdges(input) {
442
619
  // the L-R9 bans (shared segment, transversal crossing) are enforced against
443
620
  // these, and reserved through them.
444
621
  const pairFull = new Map();
622
+ // Cross-pair spacing state (active only when `useSpacing` is true).
623
+ const fixedH = [];
624
+ const fixedV = [];
625
+ const fixedElbows = [];
626
+ const recordFixedRoute = (full) => {
627
+ if (!useSpacing)
628
+ return;
629
+ for (let k = 1; k < full.length; k += 1) {
630
+ const a = full[k - 1];
631
+ const b = full[k];
632
+ if (Math.abs(a.y - b.y) <= SPACING_EPS && Math.abs(a.x - b.x) > SPACING_EPS) {
633
+ fixedH.push({ y: (a.y + b.y) / 2, lo: Math.min(a.x, b.x), hi: Math.max(a.x, b.x) });
634
+ }
635
+ else if (Math.abs(a.x - b.x) <= SPACING_EPS && Math.abs(a.y - b.y) > SPACING_EPS) {
636
+ fixedV.push({ x: (a.x + b.x) / 2, lo: Math.min(a.y, b.y), hi: Math.max(a.y, b.y) });
637
+ }
638
+ }
639
+ for (let k = 1; k + 1 < full.length; k += 1) {
640
+ fixedElbows.push(full[k]);
641
+ }
642
+ };
445
643
  let generation = 0;
446
644
  const heap = new LexHeap();
447
645
  const routes = new Map();
@@ -523,7 +721,51 @@ export function routeEdges(input) {
523
721
  }
524
722
  return best;
525
723
  };
526
- for (const request of permuteFlowRuns([...requests].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)), (request) => request.flowRun, (request) => request.flowRank)) {
724
+ const priority = input.priority;
725
+ const orderedRequests = permuteFlowRuns([...requests].sort((a, b) => {
726
+ if (useSpacing) {
727
+ if (priority !== undefined) {
728
+ const aPri = priority.has(a.id) ? 0 : 1;
729
+ const bPri = priority.has(b.id) ? 0 : 1;
730
+ if (aPri !== bPri)
731
+ return aPri - bPri;
732
+ }
733
+ const aInternal = a.within !== undefined ? 0 : 1;
734
+ const bInternal = b.within !== undefined ? 0 : 1;
735
+ if (aInternal !== bInternal)
736
+ return aInternal - bInternal;
737
+ const aDist = Math.abs(a.start.x - a.end.x) + Math.abs(a.start.y - a.end.y);
738
+ const bDist = Math.abs(b.start.x - b.end.x) + Math.abs(b.start.y - b.end.y);
739
+ if (Math.abs(aDist - bDist) > SPACING_EPS)
740
+ return aDist - bDist;
741
+ }
742
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
743
+ }), (request) => request.flowRun, (request) => request.flowRank);
744
+ // Precompute fixed dock stubs for every request so earlier routes never walk
745
+ // across or drop elbows onto a later request's already-fixed dock exit.
746
+ const samePoint = (a, b) => Math.abs(a.x - b.x) <= SPACING_EPS && Math.abs(a.y - b.y) <= SPACING_EPS;
747
+ const dockStubs = orderedRequests.map((req) => {
748
+ const sp = clearancePoint(req.start, req.startExit);
749
+ const ep = clearancePoint(req.end, req.endExit);
750
+ return { start: req.start, startPoint: sp, end: req.end, endPoint: ep };
751
+ });
752
+ const sharedBlockedElbow = useSpacing ? new Uint8Array(nx * ny) : undefined;
753
+ const sharedStrictH = useSpacing ? new Uint8Array(nx * ny) : undefined;
754
+ const sharedStrictV = useSpacing ? new Uint8Array(nx * ny) : undefined;
755
+ const lowerBound = (arr, target) => {
756
+ let lo = 0;
757
+ let hi = arr.length;
758
+ while (lo < hi) {
759
+ const mid = (lo + hi) >>> 1;
760
+ if (arr[mid] < target)
761
+ lo = mid + 1;
762
+ else
763
+ hi = mid;
764
+ }
765
+ return lo;
766
+ };
767
+ for (let reqIndex = 0; reqIndex < orderedRequests.length; reqIndex += 1) {
768
+ const request = orderedRequests[reqIndex];
527
769
  let goalParent = -1;
528
770
  let pairId = pairIds.get(request.pairKey);
529
771
  if (pairId === undefined) {
@@ -533,38 +775,310 @@ export function routeEdges(input) {
533
775
  const pid = pairId;
534
776
  const earlier = pairFull.get(request.pairKey) ?? [];
535
777
  const hasSamePair = earlier.length > 0;
536
- const startPoint = clearancePoint(request.start, request.startExit);
537
- const endPoint = clearancePoint(request.end, request.endExit);
538
- // BF-3: first inside the containment rectangle, then — only when nothing
539
- // is admissible there — without it.
540
- const clamps = request.within === undefined ? [undefined] : [request.within, undefined];
778
+ const startPoint = dockStubs[reqIndex].startPoint;
779
+ const endPoint = dockStubs[reqIndex].endPoint;
780
+ // Precompute O(1) grid-unit strict-spacing masks once per request,
781
+ // combining already-routed segments/elbows with remaining requests' fixed dock stubs.
782
+ let nearH;
783
+ let nearV;
784
+ let blockedElbow;
785
+ let strictUnitH;
786
+ let strictUnitV;
787
+ const futurePointH = [];
788
+ const futurePointV = [];
789
+ if (useSpacing) {
790
+ const futureH = [];
791
+ const futureV = [];
792
+ const futureClearancePts = [];
793
+ const pushStub = (dock, cp) => {
794
+ // Skip stubs sharing the exact same port point as the current request.
795
+ if (samePoint(dock, request.start) || samePoint(dock, request.end))
796
+ return;
797
+ if (Math.abs(dock.y - cp.y) <= SPACING_EPS && Math.abs(dock.x - cp.x) > SPACING_EPS) {
798
+ futureH.push({ y: (dock.y + cp.y) / 2, lo: Math.min(dock.x, cp.x), hi: Math.max(dock.x, cp.x) });
799
+ futurePointV.push({ x: cp.x, y: cp.y });
800
+ }
801
+ else if (Math.abs(dock.x - cp.x) <= SPACING_EPS && Math.abs(dock.y - cp.y) > SPACING_EPS) {
802
+ futureV.push({ x: (dock.x + cp.x) / 2, lo: Math.min(dock.y, cp.y), hi: Math.max(dock.y, cp.y) });
803
+ futurePointH.push({ y: cp.y, x: cp.x });
804
+ }
805
+ futureClearancePts.push(cp);
806
+ };
807
+ for (let otherIdx = reqIndex + 1; otherIdx < dockStubs.length; otherIdx += 1) {
808
+ const stub = dockStubs[otherIdx];
809
+ pushStub(stub.start, stub.startPoint);
810
+ pushStub(stub.end, stub.endPoint);
811
+ }
812
+ const allH = futureH.length > 0 ? [...fixedH, ...futureH] : fixedH;
813
+ const allV = futureV.length > 0 ? [...fixedV, ...futureV] : fixedV;
814
+ const allElbows = futureClearancePts.length > 0 ? [...fixedElbows, ...futureClearancePts] : fixedElbows;
815
+ if (allH.length > 0 || allV.length > 0 || allElbows.length > 0) {
816
+ const r = routeSpacing - SPACING_EPS;
817
+ nearH = Array.from({ length: ny }, () => []);
818
+ strictUnitH = sharedStrictH;
819
+ strictUnitH.fill(0);
820
+ for (const seg of allH) {
821
+ const iLo = Math.max(0, lowerBound(xs, seg.lo + SPACING_EPS) - 1);
822
+ for (let j = lowerBound(ys, seg.y - r); j < ny && ys[j] < seg.y + r; j += 1) {
823
+ nearH[j].push(seg);
824
+ const rowOff = j * nx;
825
+ for (let ui = iLo; ui < nx - 1 && xs[ui] < seg.hi - SPACING_EPS; ui += 1) {
826
+ if (xs[ui + 1] > seg.lo + SPACING_EPS)
827
+ strictUnitH[rowOff + ui] = 1;
828
+ }
829
+ }
830
+ }
831
+ for (const pt of futurePointH) {
832
+ const j = yIndex.get(pt.y);
833
+ if (j === undefined)
834
+ continue;
835
+ const rowOff = j * nx;
836
+ const iStart = Math.max(0, lowerBound(xs, pt.x - SPACING_EPS) - 1);
837
+ for (let ui = iStart; ui < nx - 1 && xs[ui] <= pt.x + SPACING_EPS; ui += 1) {
838
+ if (xs[ui + 1] >= pt.x - SPACING_EPS)
839
+ strictUnitH[rowOff + ui] = 1;
840
+ }
841
+ }
842
+ nearV = Array.from({ length: nx }, () => []);
843
+ strictUnitV = sharedStrictV;
844
+ strictUnitV.fill(0);
845
+ for (const seg of allV) {
846
+ const jLo = Math.max(0, lowerBound(ys, seg.lo + SPACING_EPS) - 1);
847
+ for (let i = lowerBound(xs, seg.x - r); i < nx && xs[i] < seg.x + r; i += 1) {
848
+ nearV[i].push(seg);
849
+ for (let uj = jLo; uj < ny - 1 && ys[uj] < seg.hi - SPACING_EPS; uj += 1) {
850
+ if (ys[uj + 1] > seg.lo + SPACING_EPS)
851
+ strictUnitV[uj * nx + i] = 1;
852
+ }
853
+ }
854
+ }
855
+ for (const pt of futurePointV) {
856
+ const i = xIndex.get(pt.x);
857
+ if (i === undefined)
858
+ continue;
859
+ const jStart = Math.max(0, lowerBound(ys, pt.y - SPACING_EPS) - 1);
860
+ for (let uj = jStart; uj < ny - 1 && ys[uj] <= pt.y + SPACING_EPS; uj += 1) {
861
+ if (ys[uj + 1] >= pt.y - SPACING_EPS)
862
+ strictUnitV[uj * nx + i] = 1;
863
+ }
864
+ }
865
+ blockedElbow = sharedBlockedElbow;
866
+ blockedElbow.fill(0);
867
+ if (allElbows.length > 0) {
868
+ const r2 = r * r;
869
+ for (const e of allElbows) {
870
+ const jStart = lowerBound(ys, e.y - r);
871
+ const iStart = lowerBound(xs, e.x - r);
872
+ for (let j = jStart; j < ny && ys[j] < e.y + r; j += 1) {
873
+ const dy = ys[j] - e.y;
874
+ const dy2 = dy * dy;
875
+ const rowOff = j * nx;
876
+ for (let i = iStart; i < nx && xs[i] < e.x + r; i += 1) {
877
+ const dx = xs[i] - e.x;
878
+ if (dx * dx + dy2 < r2)
879
+ blockedElbow[rowOff + i] = 1;
880
+ }
881
+ }
882
+ }
883
+ }
884
+ }
885
+ }
886
+ const violatesFixedH = (j, xA, xB) => {
887
+ const list = nearH?.[j];
888
+ const lo = Math.min(xA, xB);
889
+ const hi = Math.max(xA, xB);
890
+ if (hi - lo <= SPACING_EPS)
891
+ return false;
892
+ if (list !== undefined) {
893
+ for (const seg of list) {
894
+ if (Math.min(hi, seg.hi) - Math.max(lo, seg.lo) > SPACING_EPS)
895
+ return true;
896
+ }
897
+ }
898
+ const y = ys[j];
899
+ for (const pt of futurePointH) {
900
+ if (Math.abs(y - pt.y) <= SPACING_EPS && pt.x >= lo - SPACING_EPS && pt.x <= hi + SPACING_EPS) {
901
+ return true;
902
+ }
903
+ }
904
+ return false;
905
+ };
906
+ const violatesFixedV = (i, yA, yB) => {
907
+ const list = nearV?.[i];
908
+ const lo = Math.min(yA, yB);
909
+ const hi = Math.max(yA, yB);
910
+ if (hi - lo <= SPACING_EPS)
911
+ return false;
912
+ if (list !== undefined) {
913
+ for (const seg of list) {
914
+ if (Math.min(hi, seg.hi) - Math.max(lo, seg.lo) > SPACING_EPS)
915
+ return true;
916
+ }
917
+ }
918
+ const x = xs[i];
919
+ for (const pt of futurePointV) {
920
+ if (Math.abs(x - pt.x) <= SPACING_EPS && pt.y >= lo - SPACING_EPS && pt.y <= hi + SPACING_EPS) {
921
+ return true;
922
+ }
923
+ }
924
+ return false;
925
+ };
926
+ const violatesFixedSegment = (a, b) => {
927
+ if (Math.abs(a.y - b.y) <= SPACING_EPS) {
928
+ const j = yIndex.get(a.y);
929
+ if (j !== undefined)
930
+ return violatesFixedH(j, a.x, b.x);
931
+ const lo = Math.min(a.x, b.x);
932
+ const hi = Math.max(a.x, b.x);
933
+ return hi - lo > SPACING_EPS && fixedH.some((seg) => Math.abs(seg.y - a.y) < routeSpacing - SPACING_EPS && Math.min(hi, seg.hi) - Math.max(lo, seg.lo) > SPACING_EPS);
934
+ }
935
+ if (Math.abs(a.x - b.x) <= SPACING_EPS) {
936
+ const i = xIndex.get(a.x);
937
+ if (i !== undefined)
938
+ return violatesFixedV(i, a.y, b.y);
939
+ const lo = Math.min(a.y, b.y);
940
+ const hi = Math.max(a.y, b.y);
941
+ return hi - lo > SPACING_EPS && fixedV.some((seg) => Math.abs(seg.x - a.x) < routeSpacing - SPACING_EPS && Math.min(hi, seg.hi) - Math.max(lo, seg.lo) > SPACING_EPS);
942
+ }
943
+ return false;
944
+ };
945
+ const overlapsAnyFixedSegment = (a, b) => {
946
+ if (Math.abs(a.y - b.y) <= SPACING_EPS) {
947
+ const lo = Math.min(a.x, b.x);
948
+ const hi = Math.max(a.x, b.x);
949
+ if (hi - lo <= SPACING_EPS)
950
+ return false;
951
+ const j = yIndex.get(a.y);
952
+ const list = j !== undefined ? nearH?.[j] : fixedH;
953
+ return list !== undefined && list.some((seg) => Math.abs(seg.y - a.y) <= SPACING_EPS && Math.min(hi, seg.hi) - Math.max(lo, seg.lo) > SPACING_EPS);
954
+ }
955
+ if (Math.abs(a.x - b.x) <= SPACING_EPS) {
956
+ const lo = Math.min(a.y, b.y);
957
+ const hi = Math.max(a.y, b.y);
958
+ if (hi - lo <= SPACING_EPS)
959
+ return false;
960
+ const i = xIndex.get(a.x);
961
+ const list = i !== undefined ? nearV?.[i] : fixedV;
962
+ return list !== undefined && list.some((seg) => Math.abs(seg.x - a.x) <= SPACING_EPS && Math.min(hi, seg.hi) - Math.max(lo, seg.lo) > SPACING_EPS);
963
+ }
964
+ return false;
965
+ };
966
+ const tiers = [];
967
+ if (useSpacing) {
968
+ const hasOtherGeometry = nearH !== undefined;
969
+ if (request.within !== undefined) {
970
+ if (hasOtherGeometry) {
971
+ tiers.push({ clamp: request.within, strictSpacing: true, allowCrossPairOverlap: false });
972
+ }
973
+ tiers.push({ clamp: request.within, strictSpacing: false, allowCrossPairOverlap: false });
974
+ tiers.push({ clamp: request.within, strictSpacing: false, allowCrossPairOverlap: true });
975
+ if (hasOtherGeometry) {
976
+ tiers.push({ clamp: undefined, strictSpacing: true, allowCrossPairOverlap: false });
977
+ }
978
+ tiers.push({ clamp: undefined, strictSpacing: false, allowCrossPairOverlap: false });
979
+ tiers.push({ clamp: undefined, strictSpacing: false, allowCrossPairOverlap: true });
980
+ }
981
+ else {
982
+ if (hasOtherGeometry) {
983
+ tiers.push({ clamp: undefined, strictSpacing: true, allowCrossPairOverlap: false });
984
+ }
985
+ tiers.push({ clamp: undefined, strictSpacing: false, allowCrossPairOverlap: false });
986
+ tiers.push({ clamp: undefined, strictSpacing: false, allowCrossPairOverlap: true });
987
+ }
988
+ }
989
+ else if (request.within !== undefined) {
990
+ tiers.push({ clamp: request.within, strictSpacing: false, allowCrossPairOverlap: true });
991
+ tiers.push({ clamp: undefined, strictSpacing: false, allowCrossPairOverlap: true });
992
+ }
993
+ else {
994
+ tiers.push({ clamp: undefined, strictSpacing: false, allowCrossPairOverlap: true });
995
+ }
541
996
  let terminalObstructed = false;
542
- for (const clamp of clamps) {
997
+ let winningClamp = request.within;
998
+ const excluded = obstacles.filter((o) => request.passable.has(o.id));
999
+ const excludedEmpty = excluded.length === 0;
1000
+ const passableRects = useSpacing
1001
+ ? excluded.map((o) => rects.get(o.id)).filter((r) => r !== undefined)
1002
+ : [];
1003
+ const passWallRow = passableRects.length > 0 ? new Uint8Array(ny) : undefined;
1004
+ const passWallCol = passableRects.length > 0 ? new Uint8Array(nx) : undefined;
1005
+ if (passWallRow !== undefined && passWallCol !== undefined) {
1006
+ const c = clearance - SPACING_EPS;
1007
+ for (const r of passableRects) {
1008
+ for (const wy of [r.y, r.y + r.height]) {
1009
+ for (let j = lowerBound(ys, wy - c); j < ny && ys[j] < wy + c; j += 1)
1010
+ passWallRow[j] = 1;
1011
+ }
1012
+ for (const wx of [r.x, r.x + r.width]) {
1013
+ for (let i = lowerBound(xs, wx - c); i < nx && xs[i] < wx + c; i += 1)
1014
+ passWallCol[i] = 1;
1015
+ }
1016
+ }
1017
+ }
1018
+ const passableWallBlockedH = (ui, j) => {
1019
+ if (passWallRow[j] === 0)
1020
+ return false;
1021
+ const y = ys[j];
1022
+ const xLo = xs[ui];
1023
+ const xHi = xs[ui + 1];
1024
+ for (const r of passableRects) {
1025
+ if (xHi <= r.x - clearance + SPACING_EPS || xLo >= r.x + r.width + clearance - SPACING_EPS)
1026
+ continue;
1027
+ if (Math.abs(y - r.y) < clearance - SPACING_EPS || Math.abs(y - (r.y + r.height)) < clearance - SPACING_EPS) {
1028
+ return true;
1029
+ }
1030
+ }
1031
+ return false;
1032
+ };
1033
+ const passableWallBlockedV = (i, uj) => {
1034
+ if (passWallCol[i] === 0)
1035
+ return false;
1036
+ const x = xs[i];
1037
+ const yLo = ys[uj];
1038
+ const yHi = ys[uj + 1];
1039
+ for (const r of passableRects) {
1040
+ if (yHi <= r.y - clearance + SPACING_EPS || yLo >= r.y + r.height + clearance - SPACING_EPS)
1041
+ continue;
1042
+ if (Math.abs(x - r.x) < clearance - SPACING_EPS || Math.abs(x - (r.x + r.width)) < clearance - SPACING_EPS) {
1043
+ return true;
1044
+ }
1045
+ }
1046
+ return false;
1047
+ };
1048
+ const startViolatesStrict = useSpacing && violatesFixedSegment(request.start, startPoint);
1049
+ const endViolatesStrict = useSpacing && violatesFixedSegment(endPoint, request.end);
1050
+ for (const tier of tiers) {
543
1051
  if (goalParent >= 0 || terminalObstructed)
544
1052
  break;
545
- if (clamp === undefined && request.within !== undefined)
546
- escaped.push(request.id);
1053
+ const { clamp, strictSpacing, allowCrossPairOverlap } = tier;
1054
+ // O(1) feasibility pre-check for strictSpacing: if either fixed dock stub
1055
+ // already violates strict spacing with an existing route, no strict path can
1056
+ // close; skip straight to the next tier instead of exhausting A*.
1057
+ if (strictSpacing && (startViolatesStrict || endViolatesStrict))
1058
+ continue;
547
1059
  const insideClamp = (x, y) => clamp === undefined ||
548
1060
  (x >= clamp.x && x <= clamp.x + clamp.width && y >= clamp.y && y <= clamp.y + clamp.height);
549
1061
  if (!insideClamp(startPoint.x, startPoint.y) || !insideClamp(endPoint.x, endPoint.y))
550
1062
  continue;
551
1063
  generation += 1;
552
1064
  heap.clear();
553
- const excluded = obstacles.filter((o) => request.passable.has(o.id));
554
- const excludedEmpty = excluded.length === 0;
555
1065
  const blockedH = (i, j) => {
556
1066
  let count = coverH[j * nx + i];
557
1067
  for (const o of excluded)
558
1068
  if (coversH(o, i, j))
559
1069
  count -= 1;
560
- return count > 0;
1070
+ if (count > 0)
1071
+ return true;
1072
+ return passableRects.length > 0 && passableWallBlockedH(i, j);
561
1073
  };
562
1074
  const blockedV = (i, j) => {
563
1075
  let count = coverV[j * nx + i];
564
1076
  for (const o of excluded)
565
1077
  if (coversV(o, i, j))
566
1078
  count -= 1;
567
- return count > 0;
1079
+ if (count > 0)
1080
+ return true;
1081
+ return passableRects.length > 0 && passableWallBlockedV(i, j);
568
1082
  };
569
1083
  const blockedHFast = (i, j) => coverH[j * nx + i] > 0;
570
1084
  const blockedVFast = (i, j) => coverV[j * nx + i] > 0;
@@ -576,6 +1090,31 @@ export function routeEdges(input) {
576
1090
  const tj = yIndex.get(endPoint.y);
577
1091
  const startHeading = headingOf(request.startExit);
578
1092
  const arrival = headingOf({ x: -request.endExit.x, y: -request.endExit.y });
1093
+ if (strictSpacing && blockedElbow !== undefined && blockedElbow[tj * nx + ti] === 1 && !(si === ti && sj === tj && startHeading === arrival)) {
1094
+ // Turning at the target clearance point is forbidden; only a straight arrival
1095
+ // along `arrival` can close. Check if that single incoming unit is passable.
1096
+ const pi = ti - DX[arrival];
1097
+ const pj = tj - DY[arrival];
1098
+ let straightIncomingOk = pi >= 0 && pj >= 0 && pi < nx && pj < ny && insideClamp(xs[pi], ys[pj]);
1099
+ if (straightIncomingOk) {
1100
+ if (arrival % 2 === 0) {
1101
+ const ui = Math.min(pi, ti);
1102
+ const u = (tj * nx + ui) * 2;
1103
+ if (isBlockedH(ui, tj) || isOccupied(u) || (strictUnitH !== undefined && strictUnitH[tj * nx + ui] === 1)) {
1104
+ straightIncomingOk = false;
1105
+ }
1106
+ }
1107
+ else {
1108
+ const uj = Math.min(pj, tj);
1109
+ const u = (uj * nx + ti) * 2 + 1;
1110
+ if (isBlockedV(ti, uj) || isOccupied(u) || (strictUnitV !== undefined && strictUnitV[uj * nx + ti] === 1)) {
1111
+ straightIncomingOk = false;
1112
+ }
1113
+ }
1114
+ }
1115
+ if (!straightIncomingOk)
1116
+ continue;
1117
+ }
579
1118
  const goalState = nStates; // virtual
580
1119
  // The two dock-to-clearance joins are fixed by docking: when either
581
1120
  // already shares a segment with — or transversally crosses — an earlier
@@ -603,6 +1142,7 @@ export function routeEdges(input) {
603
1142
  heap.push(heuristicB(si, sj, startHeading), heuristicL(si, sj), startState);
604
1143
  let goalBends = Number.POSITIVE_INFINITY;
605
1144
  let goalLen = Number.POSITIVE_INFINITY;
1145
+ let pops = 0;
606
1146
  while (heap.size > 0) {
607
1147
  const state = heap.pop();
608
1148
  if (state === goalState)
@@ -610,6 +1150,8 @@ export function routeEdges(input) {
610
1150
  if (closed[state] === generation)
611
1151
  continue;
612
1152
  closed[state] = generation;
1153
+ if (strictSpacing && ++pops > 24000)
1154
+ break;
613
1155
  const h = state & 3;
614
1156
  const point = state >> 2;
615
1157
  const i = point % nx;
@@ -618,12 +1160,43 @@ export function routeEdges(input) {
618
1160
  const gl = gLen[state];
619
1161
  if (i === ti && j === tj) {
620
1162
  if ((h + 2) % 4 !== arrival) {
1163
+ let closeAllowed = true;
1164
+ if (strictSpacing) {
1165
+ if (h === arrival) {
1166
+ const straightStart = runSI[state] === si && runSJ[state] === sj && h === startHeading;
1167
+ const a1 = straightStart ? request.start : { x: xs[runSI[state]], y: ys[runSJ[state]] };
1168
+ if (violatesFixedSegment(a1, request.end))
1169
+ closeAllowed = false;
1170
+ }
1171
+ else {
1172
+ if (blockedElbow !== undefined && blockedElbow[tj * nx + ti] === 1)
1173
+ closeAllowed = false;
1174
+ else if (violatesFixedSegment(endPoint, request.end))
1175
+ closeAllowed = false;
1176
+ else if (si === ti && sj === tj && violatesFixedSegment(request.start, startPoint))
1177
+ closeAllowed = false;
1178
+ }
1179
+ }
1180
+ else if (!allowCrossPairOverlap) {
1181
+ if (h === arrival) {
1182
+ const straightStart = runSI[state] === si && runSJ[state] === sj && h === startHeading;
1183
+ const a1 = straightStart ? request.start : { x: xs[runSI[state]], y: ys[runSJ[state]] };
1184
+ if (overlapsAnyFixedSegment(a1, request.end))
1185
+ closeAllowed = false;
1186
+ }
1187
+ else if (overlapsAnyFixedSegment(endPoint, request.end)) {
1188
+ closeAllowed = false;
1189
+ }
1190
+ }
621
1191
  // When the arrival is straight (`h === arrival`), `simplifyRoute`
622
1192
  // merges the last grid run with the target dock-to-clearance join
623
1193
  // (endPoint to dock, same line): the closing check runs on the
624
1194
  // merged run-start-to-dock segment, so a crossing at the clearance
625
1195
  // point is still forbidden (L-R9, joins included).
626
- if (hasSamePair && h === arrival) {
1196
+ if (!closeAllowed) {
1197
+ // Try another arrival heading or track.
1198
+ }
1199
+ else if (hasSamePair && h === arrival) {
627
1200
  const a1 = { x: xs[runSI[state]], y: ys[runSJ[state]] };
628
1201
  if (crossesSamePair(a1, request.end, earlier) || sharesSamePair(a1, request.end, earlier)) {
629
1202
  // No closing via this straight arrival: another heading or a
@@ -682,7 +1255,7 @@ export function routeEdges(input) {
682
1255
  length = ys[uj + 1] - ys[uj];
683
1256
  }
684
1257
  const occupied = isOccupied(unit);
685
- if (occupied && isUsedBy(unit, pid))
1258
+ if (occupied && (!allowCrossPairOverlap || isUsedBy(unit, pid)))
686
1259
  continue;
687
1260
  // The candidate's current straight run, from its last bend (or the
688
1261
  // start clearance point) to the new point: the transversal and
@@ -704,6 +1277,30 @@ export function routeEdges(input) {
704
1277
  nrsx = i;
705
1278
  nrsy = j;
706
1279
  }
1280
+ if (strictSpacing) {
1281
+ if (nh !== h) {
1282
+ if (blockedElbow !== undefined && blockedElbow[j * nx + i] === 1)
1283
+ continue;
1284
+ if (i === si && j === sj && violatesFixedSegment(request.start, startPoint))
1285
+ continue;
1286
+ }
1287
+ if (nh % 2 === 0) {
1288
+ if (strictUnitH !== undefined && strictUnitH[j * nx + Math.min(i, ni)] === 1)
1289
+ continue;
1290
+ if (i === si && j === sj && nh === startHeading && violatesFixedH(j, request.start.x, startPoint.x))
1291
+ continue;
1292
+ }
1293
+ else {
1294
+ if (strictUnitV !== undefined && strictUnitV[Math.min(j, nj) * nx + i] === 1)
1295
+ continue;
1296
+ if (i === si && j === sj && nh === startHeading && violatesFixedV(i, request.start.y, startPoint.y))
1297
+ continue;
1298
+ }
1299
+ }
1300
+ else if (!allowCrossPairOverlap) {
1301
+ if (i === si && j === sj && nh === startHeading && overlapsAnyFixedSegment(request.start, startPoint))
1302
+ continue;
1303
+ }
707
1304
  if (hasSamePair) {
708
1305
  const straightStart = nrsx === si && nrsy === sj && nh === startHeading;
709
1306
  const a1 = straightStart ? request.start : { x: xs[nrsx], y: ys[nrsy] };
@@ -712,6 +1309,9 @@ export function routeEdges(input) {
712
1309
  continue;
713
1310
  }
714
1311
  const nb = gb + (nh === h ? 0 : 1);
1312
+ const hb = heuristicB(ni, nj, nh);
1313
+ if (strictSpacing && nb + hb > 12)
1314
+ continue;
715
1315
  const nl = gl + length * (occupied ? 1 + OVERLAP_PENALTY : 1);
716
1316
  const next = (nj * nx + ni) * 4 + nh;
717
1317
  if (stamp[next] === generation) {
@@ -731,9 +1331,14 @@ export function routeEdges(input) {
731
1331
  runSI[next] = nrsx;
732
1332
  runSJ[next] = nrsy;
733
1333
  parent[next] = state;
734
- heap.push(nb + heuristicB(ni, nj, nh), nl + heuristicL(ni, nj), next);
1334
+ heap.push(nb + hb, nl + heuristicL(ni, nj), next);
735
1335
  }
736
1336
  }
1337
+ if (goalParent >= 0)
1338
+ winningClamp = clamp;
1339
+ }
1340
+ if (goalParent >= 0 && winningClamp === undefined && request.within !== undefined) {
1341
+ escaped.push(request.id);
737
1342
  }
738
1343
  if (goalParent < 0) {
739
1344
  // MAJ-2: retry with reduced 2 px inflation is covered by the outer-lane
@@ -747,6 +1352,7 @@ export function routeEdges(input) {
747
1352
  const list = pairFull.get(request.pairKey) ?? [];
748
1353
  list.push(full);
749
1354
  pairFull.set(request.pairKey, list);
1355
+ recordFixedRoute(full);
750
1356
  reserveGridPath([startPoint, ...elbow, endPoint], pid);
751
1357
  continue;
752
1358
  }
@@ -806,6 +1412,7 @@ export function routeEdges(input) {
806
1412
  const list = pairFull.get(request.pairKey) ?? [];
807
1413
  list.push(fallback);
808
1414
  pairFull.set(request.pairKey, list);
1415
+ recordFixedRoute(fallback);
809
1416
  reserveGridPath([startPoint, ...elbow, endPoint], pid);
810
1417
  continue;
811
1418
  }
@@ -815,6 +1422,7 @@ export function routeEdges(input) {
815
1422
  const list = pairFull.get(request.pairKey) ?? [];
816
1423
  list.push(full);
817
1424
  pairFull.set(request.pairKey, list);
1425
+ recordFixedRoute(full);
818
1426
  }
819
1427
  return { routes, obstructed, escaped };
820
1428
  }