@knowvah/dot-engine 2.12.1 → 2.12.2

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 (129) hide show
  1. package/dist/api/builder.d.ts +7 -1
  2. package/dist/api/builder.d.ts.map +1 -1
  3. package/dist/api.js +14 -7
  4. package/dist/api.js.map +2 -2
  5. package/dist/common/edge-label-init.d.ts +26 -1
  6. package/dist/common/edge-label-init.d.ts.map +1 -1
  7. package/dist/common/nodeinit.d.ts +16 -2
  8. package/dist/common/nodeinit.d.ts.map +1 -1
  9. package/dist/common/splines-path-begin.d.ts.map +1 -1
  10. package/dist/common/splines-path-end.d.ts.map +1 -1
  11. package/dist/gvc/context.d.ts +8 -0
  12. package/dist/gvc/context.d.ts.map +1 -1
  13. package/dist/gvc/emit-gates.d.ts +5 -10
  14. package/dist/gvc/emit-gates.d.ts.map +1 -1
  15. package/dist/gvc/emit-xdot.d.ts +7 -6
  16. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  17. package/dist/gvc/job.d.ts +5 -2
  18. package/dist/gvc/job.d.ts.map +1 -1
  19. package/dist/gvc/viewport.d.ts +10 -5
  20. package/dist/gvc/viewport.d.ts.map +1 -1
  21. package/dist/index.js +361 -194
  22. package/dist/index.js.map +4 -4
  23. package/dist/layout/dot/edge-route.d.ts +7 -3
  24. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  25. package/dist/layout/dot/fastgr.d.ts +5 -3
  26. package/dist/layout/dot/fastgr.d.ts.map +1 -1
  27. package/dist/layout/dot/flat-adj-record.d.ts +22 -0
  28. package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
  29. package/dist/layout/dot/init.d.ts +49 -9
  30. package/dist/layout/dot/init.d.ts.map +1 -1
  31. package/dist/layout/dot/mincross-build.d.ts +6 -0
  32. package/dist/layout/dot/mincross-build.d.ts.map +1 -1
  33. package/dist/layout/dot/position-aux.d.ts +7 -1
  34. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  35. package/dist/layout/dot/splines-clone.d.ts +2 -1
  36. package/dist/layout/dot/splines-clone.d.ts.map +1 -1
  37. package/dist/layout/dot/splines-flat-labeled.d.ts.map +1 -1
  38. package/dist/layout/dot/splines-flat.d.ts +18 -0
  39. package/dist/layout/dot/splines-flat.d.ts.map +1 -1
  40. package/dist/layout/dot/splines-groups.d.ts.map +1 -1
  41. package/dist/layout/fdp/ports.d.ts.map +1 -1
  42. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  43. package/dist/layout/neato/sgd.d.ts.map +1 -1
  44. package/dist/model/cgraph-ops.d.ts +10 -2
  45. package/dist/model/cgraph-ops.d.ts.map +1 -1
  46. package/dist/model/edge.d.ts +7 -2
  47. package/dist/model/edge.d.ts.map +1 -1
  48. package/dist/model/edgeInfo.d.ts +17 -2
  49. package/dist/model/edgeInfo.d.ts.map +1 -1
  50. package/dist/model/graph.d.ts +4 -3
  51. package/dist/model/graph.d.ts.map +1 -1
  52. package/dist/model/lazy-attrs.d.ts.map +1 -1
  53. package/dist/parser/builder.d.ts.map +1 -1
  54. package/dist/render/dot/agwrite.d.ts +5 -1
  55. package/dist/render/dot/agwrite.d.ts.map +1 -1
  56. package/dist/render/dot/attrs.d.ts +15 -4
  57. package/dist/render/dot/attrs.d.ts.map +1 -1
  58. package/dist/render/dot/write-back.d.ts +14 -0
  59. package/dist/render/dot/write-back.d.ts.map +1 -1
  60. package/dist/render/dot/xdot-ops.d.ts +20 -29
  61. package/dist/render/dot/xdot-ops.d.ts.map +1 -1
  62. package/dist/render/dot.d.ts +4 -2
  63. package/dist/render/dot.d.ts.map +1 -1
  64. package/dist/render/json-cluster-edge.d.ts +17 -4
  65. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  66. package/dist/render/json-nonfinite.d.ts +17 -0
  67. package/dist/render/json-nonfinite.d.ts.map +1 -0
  68. package/dist/render/json.d.ts +4 -0
  69. package/dist/render/json.d.ts.map +1 -1
  70. package/dist/render/map.d.ts +3 -0
  71. package/dist/render/map.d.ts.map +1 -1
  72. package/dist/render/svg-graph.d.ts.map +1 -1
  73. package/dist/render/svg-id.d.ts +10 -1
  74. package/dist/render/svg-id.d.ts.map +1 -1
  75. package/dist/render/svg.d.ts +3 -1
  76. package/dist/render/svg.d.ts.map +1 -1
  77. package/dist/render.js +360 -193
  78. package/dist/render.js.map +4 -4
  79. package/dist/util/bsd-qsort.d.ts.map +1 -1
  80. package/dist/xdot/parse.d.ts.map +1 -1
  81. package/dist/xdot/strtod.d.ts +23 -0
  82. package/dist/xdot/strtod.d.ts.map +1 -0
  83. package/package.json +1 -1
  84. package/src/api/builder.ts +8 -2
  85. package/src/common/edge-label-init.ts +43 -17
  86. package/src/common/nodeinit.ts +28 -8
  87. package/src/common/splines-path-begin.ts +4 -3
  88. package/src/common/splines-path-end.ts +4 -3
  89. package/src/gvc/context.ts +8 -0
  90. package/src/gvc/device.ts +6 -6
  91. package/src/gvc/emit-gates.ts +6 -15
  92. package/src/gvc/emit-xdot.ts +10 -11
  93. package/src/gvc/job.ts +5 -2
  94. package/src/gvc/viewport.ts +13 -7
  95. package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
  96. package/src/layout/dot/edge-route.ts +44 -49
  97. package/src/layout/dot/fastgr.ts +9 -3
  98. package/src/layout/dot/flat-adj-record.ts +68 -0
  99. package/src/layout/dot/init.ts +59 -13
  100. package/src/layout/dot/mincross-build.ts +14 -1
  101. package/src/layout/dot/position-aux.ts +10 -3
  102. package/src/layout/dot/splines-clone.ts +8 -2
  103. package/src/layout/dot/splines-flat-labeled.ts +3 -2
  104. package/src/layout/dot/splines-flat.ts +9 -19
  105. package/src/layout/dot/splines-groups.ts +5 -3
  106. package/src/layout/fdp/ports.ts +6 -2
  107. package/src/layout/neato/conjgrad-mkernel.ts +6 -2
  108. package/src/layout/neato/sgd.ts +2 -1
  109. package/src/model/cgraph-ops.ts +4 -3
  110. package/src/model/edge.ts +11 -4
  111. package/src/model/edgeInfo.ts +18 -2
  112. package/src/model/graph.ts +4 -3
  113. package/src/model/lazy-attrs.ts +3 -1
  114. package/src/parser/builder.ts +12 -3
  115. package/src/render/dot/agwrite.ts +10 -3
  116. package/src/render/dot/attrs.ts +18 -7
  117. package/src/render/dot/write-back.ts +27 -3
  118. package/src/render/dot/xdot-ops.ts +25 -56
  119. package/src/render/dot.ts +7 -5
  120. package/src/render/json-cluster-edge.ts +42 -5
  121. package/src/render/json-nonfinite.ts +51 -0
  122. package/src/render/json.ts +23 -26
  123. package/src/render/map.ts +3 -0
  124. package/src/render/svg-graph.ts +3 -15
  125. package/src/render/svg-id.ts +11 -2
  126. package/src/render/svg.ts +4 -1
  127. package/src/util/bsd-qsort.ts +2 -1
  128. package/src/xdot/parse.ts +9 -19
  129. package/src/xdot/strtod.ts +167 -0
@@ -27,7 +27,7 @@ import { linearBezier } from './edge-route-poly.js';
27
27
  import { rankEdgeInfoOf, routedThisPass } from './edge-route-rank.js';
28
28
  import { routeRegularEdgeFaithful } from './edge-route-faithful.js';
29
29
  import { isFlatAdjacent, makeFlatAdjEdges } from './splines-flat.js';
30
- import { ShapeKind, type ShapeDesc } from '../../common/types.js';
30
+ import { lostFlatAdjRecordEdge } from './flat-adj-record.js';
31
31
  import {
32
32
  collectNonAdjacentFlatGroup, routeFlatEdgeGroupFaithful,
33
33
  } from './splines-flat-multi.js';
@@ -174,7 +174,7 @@ function dispatchMultiRankNonForward(
174
174
  * adjacent regular via make_regular_edge. clipAndInstall gates head/tail arrows
175
175
  * by the dir attribute. @see lib/dotgen/dotsplines.c:make_regular_edge
176
176
  */
177
- function routeEdgeNonForward(e: GraphEdge, g: Graph): void {
177
+ function routeEdgeNonForward(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): void {
178
178
  if (routeFaithfulAdjacentBack(e, g)) return; // T1 (AD-1): faithful adjacent back edge
179
179
  const tailBox = nodeBoxOf(e.tail, g);
180
180
  const headBox = nodeBoxOf(e.head, g);
@@ -183,7 +183,7 @@ function routeEdgeNonForward(e: GraphEdge, g: Graph): void {
183
183
  // routers otherwise live only in the forward path, so reach them here too —
184
184
  // e.g. a dir=both flat adjacent side-port edge (2437: AA3:se -> AA4:sw).
185
185
  if (e.tail.info.rank !== undefined && e.tail.info.rank === e.head.info.rank
186
- && routeFlatEdge(e, g)) return;
186
+ && routeFlatEdge(e, g, run)) return;
187
187
  routeFaithfulRegularPlain(e, g);
188
188
  }
189
189
 
@@ -247,12 +247,12 @@ function routeFaithfulAdjacentBack(e: GraphEdge, g: Graph): boolean {
247
247
  return true;
248
248
  }
249
249
 
250
- /** Route and install spline + arrowhead(s) for a single edge. */
251
- export function routeOneEdge(e: GraphEdge, g: Graph): void {
250
+ /** Route and install spline + arrowhead(s) for a single edge. `run` is the
251
+ * edgecmp run the dispatch loop found `e` in ({@link routeLoneEdge}). */
252
+ export function routeOneEdge(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): void {
252
253
  const dirAttr = e.attrs.get('dir') ?? defaultEdgeDir(g);
253
- const pw = edgeRenderPenwidth(e);
254
254
  if (dirAttr !== 'forward') {
255
- routeEdgeNonForward(e, g);
255
+ routeEdgeNonForward(e, g, run);
256
256
  return;
257
257
  }
258
258
  if (routeFaithfulAdjacentBack(e, g)) return; // T1 (AD-1): faithful adjacent back edge
@@ -266,7 +266,7 @@ export function routeOneEdge(e: GraphEdge, g: Graph): void {
266
266
  routeFaithfulMultiRank(e, g); // T3 (AD-2): faithful chain pipeline
267
267
  return;
268
268
  }
269
- routeForwardEdge(e, g, tailBox, headBox, pw);
269
+ routeForwardEdge(e, g, tailBox, headBox, run);
270
270
  }
271
271
 
272
272
  /**
@@ -319,35 +319,39 @@ function isGroupableFlat(x: GraphEdge, g: Graph): boolean {
319
319
 
320
320
  /** True when a port-less adjacent flat edge shares its group with a ported one:
321
321
  * C's `ports` flag covers the whole group, so it routes via the aux graph. */
322
- function joinsPortedFlatGroup(e: GraphEdge, g: Graph): boolean {
322
+ function joinsPortedFlatGroup(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): boolean {
323
323
  return isAdjFlatCandidate(e) && isGroupableFlat(e, g)
324
- && collectAdjacentFlatGroup(e, g).some(hasDefinedPort);
324
+ && collectAdjacentFlatGroup(e, g, run).some(hasDefinedPort);
325
325
  }
326
326
 
327
327
  /**
328
- * Collect all unrouted adjacent same-rank ported flat edges between e's two
329
- * endpoints (either direction), ordered so group[0].tail is the lower-order
330
- * (left) node. C's dispatch loop sorts edges by edgecmp (equivalent edges
331
- * contiguous) and groups a run while `getmainedge(e0) === getmainedge(e1)`
332
- * (dotsplines.c:343-356); it does NOT re-derive the group from a node-pair
333
- * scan. Gate on getMainEdge equality (not just the unordered node pair) so
334
- * two independent parallel edges that merely share endpoints, but resolve to
335
- * different main edges (e.g. one is itself the main edge of a virtual chain,
336
- * the other belongs to a different original edge), are NOT folded into one
337
- * shared aux solve. C makes one make_flat_adj_edges call PER getmainedge run.
328
+ * The unrouted adjacent same-rank flat edges of `run` between e's two
329
+ * endpoints (either direction), in the run's order. C's dispatch loop sorts
330
+ * edges by edgecmp (equivalent edges contiguous), groups a run while
331
+ * `getmainedge(e0) === getmainedge(e1)` (dotsplines.c:343-356) and hands
332
+ * make_flat_edge that slice of the sorted list; it does NOT re-derive the
333
+ * group from a node-pair scan, and make_flat_adj_edges clones the aux edges
334
+ * in the slice's order (`e = edges[i]`). That order is the aux edges' AGSEQ,
335
+ * which the aux mincross reads (do_ordering_node, the install order), so the
336
+ * group must not be re-sorted here. Gate on getMainEdge equality (not just the
337
+ * unordered node pair) so two independent parallel edges that merely share
338
+ * endpoints, but resolve to different main edges (e.g. one is itself the main
339
+ * edge of a virtual chain, the other belongs to a different original edge),
340
+ * are NOT folded into one shared aux solve. C makes one make_flat_adj_edges
341
+ * call PER getmainedge run.
338
342
  * @see lib/dotgen/dotsplines.c:343-378 (esp. line 356 `if (le0 != le1) break;`)
339
343
  * @see lib/dotgen/dotsplines.c:make_flat_edge (makefwdedge of *edges), dot_splines_
344
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (clone loop over edges[i])
340
345
  */
341
- function collectAdjacentFlatGroup(e: GraphEdge, g: Graph): GraphEdge[] {
346
+ function collectAdjacentFlatGroup(
347
+ e: GraphEdge, g: Graph, run: readonly GraphEdge[],
348
+ ): GraphEdge[] {
342
349
  const u = e.tail, v = e.head;
343
- const lo = (u.info.order ?? 0) <= (v.info.order ?? 0) ? u : v;
344
350
  const me = getMainEdge(e);
345
351
  const sharesPair = (x: GraphEdge): boolean =>
346
352
  (x.tail === u && x.head === v) || (x.tail === v && x.head === u);
347
- const group = g.edges.filter(x =>
353
+ return run.filter(x =>
348
354
  sharesPair(x) && isGroupableFlat(x, g) && getMainEdge(x) === me);
349
- group.sort((a, b) => Number(b.tail === lo) - Number(a.tail === lo) || a.seq - b.seq);
350
- return group;
351
355
  }
352
356
 
353
357
  /**
@@ -360,7 +364,7 @@ function collectAdjacentFlatGroup(e: GraphEdge, g: Graph): GraphEdge[] {
360
364
  * installEdgeSpline/arrowheadPolygon here.
361
365
  * @see lib/dotgen/dotsplines.c:make_flat_edge, make_regular_edge
362
366
  */
363
- function routeFaithfulSidePort(e: GraphEdge, g: Graph): boolean {
367
+ function routeFaithfulSidePort(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): boolean {
364
368
  const sameRank = e.tail.info.rank !== undefined && e.tail.info.rank === e.head.info.rank;
365
369
  // Adjacent flat endpoints route via the rotated-aux pipeline (make_flat_adj_edges),
366
370
  // which installs the spline directly; the box channel handles non-adjacent flats.
@@ -368,7 +372,7 @@ function routeFaithfulSidePort(e: GraphEdge, g: Graph): boolean {
368
372
  // route the whole group so the reversed back edge clones auxh->auxt and curls.
369
373
  // @see lib/dotgen/dotsplines.c:dot_splines_ (ED_adjacent edge-group loop)
370
374
  if (sameRank && isFlatAdjacent(g, e)) {
371
- const group = collectAdjacentFlatGroup(e, g);
375
+ const group = collectAdjacentFlatGroup(e, g, run);
372
376
  return makeFlatAdjEdges(g, group, group.length, edgeType(g)) === 0
373
377
  && routedThisPass(e);
374
378
  }
@@ -388,19 +392,6 @@ function routeFaithfulSidePort(e: GraphEdge, g: Graph): boolean {
388
392
  return true;
389
393
  }
390
394
 
391
- /** graphviz #1323: C make_flat_adj_edges bails on a flat edge between ADJACENT
392
- * nodes with a record-shape endpoint — no spline is built, map_edge "lost"s it,
393
- * and it is never drawn. Detect that case so the router leaves e.info.spl
394
- * undefined (edgeHasDrawableContent then skips it), matching the oracle.
395
- * @see lib/dotgen/dotsplines.c:make_flat_adj_edges */
396
- function isLostFlatAdjRecordEdge(g: Graph, e: GraphEdge): boolean {
397
- const tr = e.tail.info.rank;
398
- if (tr === undefined || tr !== e.head.info.rank) return false;
399
- if (!isFlatAdjacent(g, e)) return false;
400
- const rec = (s: unknown): boolean => (s as ShapeDesc | undefined)?.kind === ShapeKind.SH_RECORD;
401
- return rec(e.tail.info.shape) || rec(e.head.info.shape);
402
- }
403
-
404
395
  /**
405
396
  * Dispatch a same-rank (flat) edge to its faithful router. C routes flat edges
406
397
  * by topology in `dot_splines_` independent of ED_dir (only the arrowheads
@@ -410,16 +401,16 @@ function isLostFlatAdjRecordEdge(g: Graph, e: GraphEdge): boolean {
410
401
  * caller fall through to the regular/fitter path.
411
402
  * @see lib/dotgen/dotsplines.c:dot_splines_ (flat edge group dispatch)
412
403
  */
413
- function routeFlatEdge(e: GraphEdge, g: Graph): boolean {
414
- if (isLostFlatAdjRecordEdge(g, e)) return true; // #1323: lost edge, leave unrouted
404
+ function routeFlatEdge(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): boolean {
405
+ if (lostFlatAdjRecordEdge(g, e)) return true; // #1323: lost edge, leave unrouted
415
406
  // Labeled same-rank edges: non-adjacent routes around the flat label vnode
416
407
  // (make_flat_labeled_edge); adjacent no-port routes straight with the label
417
408
  // above (make_flat_adj_edges → makeSimpleFlatLabels). Both decline for every
418
409
  // other edge, so only labeled flats are diverted. @see dotsplines.c:1527-1533
419
410
  if (makeFlatLabeledEdge(g, e)) return true;
420
- if (joinsPortedFlatGroup(e, g) && routeFaithfulSidePort(e, g)) return true;
411
+ if (joinsPortedFlatGroup(e, g, run) && routeFaithfulSidePort(e, g, run)) return true;
421
412
  if (makeAdjFlatNoPortEdge(g, e)) return true;
422
- if ((hasSidePort(e) || isAdjacentPortFlat(e, g)) && routeFaithfulSidePort(e, g)) return true;
413
+ if ((hasSidePort(e) || isAdjacentPortFlat(e, g)) && routeFaithfulSidePort(e, g, run)) return true;
423
414
  // Non-adjacent unlabeled flat with no side port (e.g. a same-rank cross-cluster
424
415
  // edge with an intervening node): C make_flat_edge routes it UP through the box
425
416
  // corridor, not straight through. @see lib/dotgen/dotsplines.c:make_flat_edge
@@ -435,9 +426,9 @@ function routeFlatEdge(e: GraphEdge, g: Graph): boolean {
435
426
 
436
427
  /** Route + install a plain forward edge, attaching declared ports if any. */
437
428
  function routeForwardEdge(
438
- e: GraphEdge, g: Graph, tailBox: NodeBox, headBox: NodeBox, pw: number,
429
+ e: GraphEdge, g: Graph, tailBox: NodeBox, headBox: NodeBox, run: readonly GraphEdge[],
439
430
  ): void {
440
- if (routeFlatEdge(e, g)) return;
431
+ if (routeFlatEdge(e, g, run)) return;
441
432
  // T2 (AD-1/AD-2): plain adjacent-rank forward edges route through the faithful
442
433
  // pathplan path (make_regular_edge). routeRegularEdgeFaithful declines (null)
443
434
  // for anything not adjacent-rank, so the fitter below only handles declines.
@@ -447,7 +438,8 @@ function routeForwardEdge(
447
438
  tailBox, headBox, rankInfo, edgePenwidthAttr(e), portRouteOf(e),
448
439
  );
449
440
  installEdgeSpline(e, result.bezierPts, result.arrowTip);
450
- e.info.headArrowOps = arrowDrawOpsForEnd(e, 'head', result.arrowTip, result.arrowDir, pw);
441
+ e.info.headArrowOps = arrowDrawOpsForEnd(
442
+ e, 'head', result.arrowTip, result.arrowDir, edgeRenderPenwidth(e));
451
443
  }
452
444
 
453
445
  /**
@@ -456,9 +448,12 @@ function routeForwardEdge(
456
448
  * lacking valid coords). The `dotSplines_` group loop calls it for the edges it
457
449
  * collected from the rank arrays, at their `edgecmp` position, as C does; an
458
450
  * edge it did not collect keeps the route it had, as `ED_spl` does in C.
451
+ * `run` is the edgecmp run `e` belongs to, in list order: what C passes
452
+ * make_flat_edge as `edges + ind`, `cnt`. A flat-adjacent group is taken from
453
+ * it, so the aux edges are cloned in C's order.
459
454
  * @see lib/dotgen/dotsplines.c:dot_splines_ (per-edge dispatch + 295 skip)
460
455
  */
461
- export function routeLoneEdge(e: GraphEdge, g: Graph): void {
456
+ export function routeLoneEdge(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): void {
462
457
  // A lost edge (routesplines failure, C semantics) is consumed: C routes each
463
458
  // edge exactly once, so a later group must not re-attempt it.
464
459
  if (routedThisPass(e) || e.info.lost === true) return;
@@ -480,5 +475,5 @@ export function routeLoneEdge(e: GraphEdge, g: Graph): void {
480
475
  // @see lib/dotgen/dotsplines.c:make_flat_labeled_edge, lib/common/emit.c:edge_in_box
481
476
  if (e.tail === e.head) return;
482
477
  if (!hasValidCoords(e)) return;
483
- routeOneEdge(e, g);
478
+ routeOneEdge(e, g, run);
484
479
  }
@@ -236,15 +236,21 @@ export function deleteFlatEdge(e: Edge): void {
236
236
  }
237
237
 
238
238
  /**
239
- * Add `e` to the flat graph (tail.flat_out and head.flat_in) and mark the
240
- * graph as having flat edges.
239
+ * Add `e` to the flat graph (tail.flat_out and head.flat_in) and mark `g` and
240
+ * its dot root as having flat edges. flat_reorder reads the flag of the graph
241
+ * it runs on, so an edge added through a subgraph (ordered_edges recursing
242
+ * into a rank subgraph, e.g. make_flat_adj_edges' `xxx`) must flag the root.
241
243
  * @see lib/dotgen/fastgr.c:flat_edge
242
244
  */
243
- export function flatEdge(g: import('../../model/graph.js').Graph, e: Edge): void {
245
+ export function flatEdge(g: Graph, e: Edge): void {
244
246
  if (!e.tail.info.flat_out) e.tail.info.flat_out = { list: [], size: 0 };
245
247
  if (!e.head.info.flat_in) e.head.info.flat_in = { list: [], size: 0 };
246
248
  elistAppend(e.tail.info.flat_out, e);
247
249
  elistAppend(e.head.info.flat_in, e);
250
+ // C: GD_has_flat_edges(dot_root(g)) = GD_has_flat_edges(g) = true. dot_root
251
+ // is inlined (mincross-utils.ts:dotRoot imports this module).
252
+ // @see lib/dotgen/dotinit.c:dot_root
253
+ (g.info.dotroot ?? g.root).info.has_flat_edges = true;
248
254
  g.info.has_flat_edges = true;
249
255
  }
250
256
 
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * The record exit of C `make_flat_adj_edges`: a flat edge between adjacent
5
+ * nodes one of which has a record shape gets no spline (graphviz #1323), and
6
+ * the first such edge of a process is reported.
7
+ *
8
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (1143-1152)
9
+ */
10
+
11
+ import type { Graph } from '../../model/graph.js';
12
+ import type { Edge } from '../../model/edge.js';
13
+ import type { Node } from '../../model/node.js';
14
+ import { ShapeKind, type ShapeDesc } from '../../common/types.js';
15
+ import { agerr, agwarningf } from '../../common/agerr.js';
16
+ import { registerRenderState } from '../../common/render-state.js';
17
+ import { isFlatAdjacent, flatLeadPair } from './splines-flat.js';
18
+
19
+ /** @see lib/dotgen/dotsplines.c:1145 */
20
+ export const MSG_FLAT_ADJ_RECORD =
21
+ 'flat edge between adjacent nodes one of which has a record shape - replace records with HTML-like labels';
22
+
23
+ const EDGEOP_DIRECTED = '->';
24
+ const EDGEOP_UNDIRECTED = '--';
25
+
26
+ /**
27
+ * C's `static atomic_flag warned`: one warning per process, so one per render
28
+ * here (reset at render entry, AD-4).
29
+ * @see lib/dotgen/dotsplines.c:1141
30
+ */
31
+ const flatAdjRecord = { warned: false };
32
+ registerRenderState(() => {
33
+ flatAdjRecord.warned = false;
34
+ });
35
+
36
+ /** `shapeOf(n) == SH_RECORD`. @see lib/common/shapes.c:shapeOf */
37
+ function isRecord(n: Node): boolean {
38
+ return (n.info.shape as ShapeDesc | undefined)?.kind === ShapeKind.SH_RECORD;
39
+ }
40
+
41
+ /** `agisdirected(g) ? "->" : "--"`. */
42
+ function edgeOp(g: Graph): string {
43
+ const kind = g.root.kind;
44
+ return kind === 'directed' || kind === 'strict-directed' ? EDGEOP_DIRECTED : EDGEOP_UNDIRECTED;
45
+ }
46
+
47
+ /**
48
+ * True when `e` takes the record exit, in which case the caller leaves it
49
+ * unrouted (`map_edge` then reports it lost and it is never drawn). The first
50
+ * call that takes the exit warns, naming C's `e0`: the group's lead edge after
51
+ * `make_flat_edge`'s makefwdedge, i.e. the ends in rank order, by their raw
52
+ * `agnameof` names.
53
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (1143-1152)
54
+ * @see lib/dotgen/dotsplines.c:make_flat_edge (makefwdedge of *edges)
55
+ */
56
+ export function lostFlatAdjRecordEdge(g: Graph, e: Edge): boolean {
57
+ const tr = e.tail.info.rank;
58
+ if (tr === undefined || tr !== e.head.info.rank) return false;
59
+ if (!isFlatAdjacent(g, e)) return false;
60
+ const { tn, hn } = flatLeadPair([e]);
61
+ if (!isRecord(tn) && !isRecord(hn)) return false;
62
+ if (!flatAdjRecord.warned) {
63
+ flatAdjRecord.warned = true;
64
+ agwarningf(MSG_FLAT_ADJ_RECORD);
65
+ agerr('prev', ` Edge ${tn.name} ${edgeOp(g)} ${hn.name}`);
66
+ }
67
+ return true;
68
+ }
@@ -119,26 +119,72 @@ export function dotInitNode(n: Node): void {
119
119
  // ---------------------------------------------------------------------------
120
120
 
121
121
  /**
122
- * Which of dot_init_edge's attribute symbols are bound. C reads `constraint`,
123
- * `minlen` and `group` through the globals E_constr, E_minlen and N_group
124
- * (bound per graph by graph_init). make_flat_adj_edges' setState nulls all
125
- * three for the aux layout and cleanupCloneGraph restores them, so an aux
126
- * edge's copied `constraint=false` or `minlen`, and its clones' `group`, are
127
- * never read: late_int(e, NULL, 1, 0) is 1 and late_string(n, NULL, "") "".
128
- * @see lib/common/input.c:graph_init (E_constr, E_minlen, N_group)
122
+ * Which of the attribute symbols make_flat_adj_edges' setState nulls are bound.
123
+ * C reads each attribute through a global (bound per graph by graph_init).
124
+ * setState nulls thirteen of them for the aux layout and cleanupCloneGraph
125
+ * restores them. Seven are modelled here, because a bound read changes what
126
+ * the aux graph holds:
127
+ *
128
+ * - E_constr, E_minlen, N_group (dot_init_edge): an aux edge's copied
129
+ * `constraint=false` or `minlen`, and its clones' `group`, are never read:
130
+ * late_int(e, NULL, 1, 0) is 1 and late_string(n, NULL, "") "".
131
+ * - E_headlabel, E_taillabel, E_xlabel (common_init_edge, utils.c:525-545) and
132
+ * N_xlabel (common_init_node, utils.c:443): the `sym && ...` guards fail, so
133
+ * the aux makes no head, tail or external label and sets none of their
134
+ * GD_has_labels bits. A bound read made each label a second time: a
135
+ * malformed HTML value was reported twice where native reports it once, and
136
+ * the aux postprocess (addXLabels, the aux bounding box) saw labels C never
137
+ * makes.
138
+ *
139
+ * The other six set a field on an aux object that no aux pass reads and that
140
+ * cleanupCloneGraph discards, so they have no gate. Each was probed against
141
+ * native 16.1.0 on flat-adjacent inputs that set it (issue #131: dot, xdot,
142
+ * svg and stderr equal on every input that equals native without it):
143
+ *
144
+ * - E_fontcolor (initFontEdgeAttr, utils.c:460), E_labelfontcolor
145
+ * (initFontLabelEdgeAttr, utils.c:470) and N_fontcolor (common_init_node,
146
+ * utils.c:440): the colour of an aux label. Only the aux edge label's
147
+ * position is copied back.
148
+ * - N_nojustify (poly_init, shapes.c:2133): the aux node label's space.x.
149
+ * - N_showboxes (common_init_node, utils.c:450): not read by the port's init.
150
+ * - N_style (stylenode, shapes.c:471): render only, and the aux is never
151
+ * rendered.
152
+ *
153
+ * _dot_splines' port-label pass tests `E_headlabel || E_taillabel`
154
+ * (dotsplines.c:447). The port's placePortLabels tests whether the attributes
155
+ * are declared, which is true on the aux graph. With no head or tail label on
156
+ * any aux edge its loops do nothing, which is C's result.
157
+ * @see lib/common/input.c:graph_init (E_constr, E_minlen, N_group, ...)
129
158
  * @see lib/dotgen/dotsplines.c:setState, cleanupCloneGraph
130
159
  */
131
160
  export interface InitEdgeSyms {
161
+ /** E_constr. */
132
162
  readonly constr: boolean;
163
+ /** E_minlen. */
133
164
  readonly minlen: boolean;
165
+ /** N_group. */
134
166
  readonly group: boolean;
167
+ /** E_headlabel. */
168
+ readonly headlabel: boolean;
169
+ /** E_taillabel. */
170
+ readonly taillabel: boolean;
171
+ /** E_xlabel. */
172
+ readonly xlabel: boolean;
173
+ /** N_xlabel. */
174
+ readonly nodeXlabel: boolean;
135
175
  }
136
176
 
137
177
  /** The main graph's symbols, as graph_init binds them. */
138
- export const DOT_INIT_SYMS: InitEdgeSyms = { constr: true, minlen: true, group: true };
178
+ export const DOT_INIT_SYMS: InitEdgeSyms = {
179
+ constr: true, minlen: true, group: true,
180
+ headlabel: true, taillabel: true, xlabel: true, nodeXlabel: true,
181
+ };
139
182
 
140
183
  /** The flat-adj aux graph's symbols. @see lib/dotgen/dotsplines.c:setState */
141
- export const AUX_INIT_SYMS: InitEdgeSyms = { constr: false, minlen: false, group: false };
184
+ export const AUX_INIT_SYMS: InitEdgeSyms = {
185
+ constr: false, minlen: false, group: false,
186
+ headlabel: false, taillabel: false, xlabel: false, nodeXlabel: false,
187
+ };
142
188
 
143
189
  /**
144
190
  * True when tail and head carry the same non-empty `group` attribute.
@@ -257,21 +303,21 @@ function clearFastGraphLists(n: Node): void {
257
303
  /**
258
304
  * Calls commonInitNode (shape-aware, label-driven sizing) then
259
305
  * dotInitNode for every node, then dotInitEdge for every edge. `syms` stands
260
- * for the global symbol state C's dot_init_edge reads (AUX_INIT_SYMS inside
261
- * make_flat_adj_edges).
306
+ * for the global symbol state C's dot_init_edge, common_init_node and
307
+ * common_init_edge read (AUX_INIT_SYMS inside make_flat_adj_edges).
262
308
  *
263
309
  * @see lib/dotgen/dotinit.c:dot_init_node_edge
264
310
  * @see lib/dotgen/dotinit.c:dot_init_node (common_init_node + gv_nodesize)
265
311
  */
266
312
  export function dotInitNodeEdge(g: Graph, syms: InitEdgeSyms = DOT_INIT_SYMS): void {
267
313
  for (const n of nodesInSeq(g)) {
268
- commonInitNode(n, g);
314
+ commonInitNode(n, g, syms);
269
315
  dotInitNode(n);
270
316
  }
271
317
  const measurer = g.root.info.gvc?.textMeasurer;
272
318
  for (const e of g.edges) {
273
319
  dotInitEdge(e, syms);
274
- if (measurer) initEdgeLabels(e, g, measurer);
320
+ if (measurer) initEdgeLabels(e, g, measurer, syms);
275
321
  }
276
322
  }
277
323
 
@@ -23,6 +23,8 @@ import { CLUSTER, isACluster } from './rank.js';
23
23
  import { installCluster, expandCluster, markLowclusters } from './cluster.js';
24
24
  import { agnode, agsubg, agsubnode, agGraphAttr } from '../../model/cgraph-ops.js';
25
25
  import { nodesInSeq } from './decomp.js';
26
+ import { nodeAttr } from '../../common/attr-get.js';
27
+ import { agerrorf } from '../../common/agerr.js';
26
28
 
27
29
  // betweenclust — @see lib/dotgen/mincross.c:betweenclust
28
30
  export function betweenclust(e: Edge): boolean {
@@ -338,11 +340,20 @@ export function doOrderingNode(ctx: MincrossContext, g: Graph, n: Node, outflag:
338
340
  doOrderingAddFlatEdges(g, sortlist, outflag);
339
341
  }
340
342
 
343
+ /**
344
+ * Order the nodes that carry `ordering`. C reads
345
+ * `late_string(n, N_ordering, NULL)`, which is agxget: the node's own value,
346
+ * else the `node [...]` default the node was created under ({@link nodeAttr}).
347
+ * @see lib/dotgen/mincross.c:do_ordering_for_nodes (489)
348
+ */
341
349
  export function doOrderingForNodes(ctx: MincrossContext, g: Graph): void {
342
350
  for (const n of nodesInSeq(g)) {
343
- const ordering = n.attrs.get('ordering');
351
+ const ordering = nodeAttr(n, g, 'ordering');
344
352
  if (ordering === 'out') doOrderingNode(ctx, g, n, true);
345
353
  else if (ordering === 'in') doOrderingNode(ctx, g, n, false);
354
+ else if (ordering !== undefined && ordering !== '') {
355
+ agerrorf(`ordering '${ordering}' not recognized for node '${n.name}'.`);
356
+ }
346
357
  }
347
358
  }
348
359
 
@@ -359,10 +370,12 @@ export function orderedEdges(ctx: MincrossContext, g: Graph): void {
359
370
  // does NOT recurse into subgraphs. So C silently ignores subgraph-scoped
360
371
  // ordering; only a root-level (or cluster's own) "out"/"in" is applied.
361
372
  // agGraphAttr reproduces the load-bearing "" vs undefined distinction.
373
+ // Any other non-empty value is an error (525), and still does not recurse.
362
374
  const ordering = agGraphAttr(g, 'ordering');
363
375
  if (ordering !== undefined) {
364
376
  if (ordering === 'out') doOrdering(ctx, g, true);
365
377
  else if (ordering === 'in') doOrdering(ctx, g, false);
378
+ else if (ordering !== '') agerrorf(`ordering '${ordering}' not recognized.`);
366
379
  return;
367
380
  }
368
381
  for (const subg of g.subgraphs.values()) {
@@ -99,9 +99,15 @@ export function graphRanksep(g: Graph): number { return g.info.ranksep ?? 0; }
99
99
  // make_aux_edge — @see lib/dotgen/position.c:make_aux_edge
100
100
  // ---------------------------------------------------------------------------
101
101
 
102
- /** @see lib/dotgen/position.c:make_aux_edge */
102
+ /**
103
+ * The edge's two ports are the shared default port: C zeroes them inside the
104
+ * Agedgeinfo_t it allocates here and never writes them. Its attributes are the
105
+ * shared empty map: C binds no attribute record to an aux edge, only the
106
+ * Agedgeinfo_t (issue #145).
107
+ * @see lib/dotgen/position.c:make_aux_edge
108
+ */
103
109
  export function makeAuxEdge(u: Node, v: Node, len: number, wt: number): Edge {
104
- const e = new EdgeClass(u, v, '');
110
+ const e = new EdgeClass(u, v, '', true, true);
105
111
  // C ROUND() is half away from zero. @see lib/dotgen/position.c:195
106
112
  e.info.minlen = cround(Math.min(len, 2147483647));
107
113
  e.info.weight = wt;
@@ -192,7 +198,8 @@ export function applyFlatLabel(
192
198
  const nodesep = graphNodesep(g);
193
199
  const e0 = nodeOrder(e0raw.head) <= nodeOrder(e1raw.head) ? e0raw : e1raw;
194
200
  const e1 = e0 === e0raw ? e1raw : e0raw;
195
- const m0 = edgeMinlen(e) * nodesep / 2;
201
+ // C: int m0 (position.c:222,276), so the half truncates
202
+ const m0 = Math.trunc(edgeMinlen(e) * nodesep / 2);
196
203
  const m1a = m0 + nodeRw(e0.head) + nodeLw(e0.tail);
197
204
  if (!canReach(e0.tail, e0.head)) makeAuxEdge(e0.head, e0.tail, m1a, edgeWeight(e));
198
205
  const m1b = m0 + nodeRw(e1.tail) + nodeLw(e1.head);
@@ -12,7 +12,7 @@ import type { Edge } from '../../model/edge.js';
12
12
  import type { Point } from '../../model/geom.js';
13
13
  import { Edge as EdgeClass } from '../../model/edge.js';
14
14
  import { makePort } from '../../model/edgeInfo.js';
15
- import { agnode } from '../../model/cgraph-ops.js';
15
+ import { agnode, agsubnode } from '../../model/cgraph-ops.js';
16
16
 
17
17
  /**
18
18
  * Map a point from the flat-adj auxiliary frame back to the original frame:
@@ -30,7 +30,8 @@ export function transformf(p: Point, del: Point, flip: boolean): Point {
30
30
  // ---------------------------------------------------------------------------
31
31
 
32
32
  /**
33
- * Create a copy of orign in graph g, carrying geometry from NodeInfo.
33
+ * Create a copy of orign in graph g, carrying geometry from NodeInfo. When g
34
+ * is a subgraph the copy is a member of g and of every graph above it.
34
35
  * @see lib/dotgen/dotsplines.c:cloneNode
35
36
  */
36
37
  export function cloneNode(g: Graph, orign: Node): Node {
@@ -42,6 +43,11 @@ export function cloneNode(g: Graph, orign: Node): Node {
42
43
  // the aux graph's own auxt/auxh creation order.
43
44
  // @see lib/dotgen/dotsplines.c:cloneNode (agnode(g,...,1))
44
45
  const n = agnode(g, orign.name, true)!;
46
+ // C's agnode(g, name, 1) on a subgraph installs the node into g and every
47
+ // graph above it (installnodetoroot); the port's agnode installs into the
48
+ // root only, so do the subgraph half here.
49
+ // @see lib/cgraph/node.c:agnode
50
+ if (g !== g.root) agsubnode(g, n, true);
45
51
  n.info.coord = { x: orign.info.coord.x, y: orign.info.coord.y };
46
52
  n.info.lw = orign.info.lw;
47
53
  n.info.rw = orign.info.rw;
@@ -150,8 +150,9 @@ export function makeFlatLabeledEdge(g: Graph, e: Edge): boolean {
150
150
  // Degenerate route (routesplines pn=0): label set, no spline installed — C's
151
151
  // make_flat_labeled_edge returns the same way; emit's edge_in_box then decides
152
152
  // whether the (untranslated) label overlaps the clip. Still HANDLED → true.
153
- // C's dot_splines_ visits the edge once, so mark it lost: the routeDotEdges
154
- // backstop must not route (and report the failure) a second time.
153
+ // C's dot_splines_ visits the edge once, so mark it lost: the flat group loop
154
+ // calls routeLoneEdge per member, and its `lost` skip keeps a later call from
155
+ // routing (and reporting the failure) a second time.
155
156
  if (ps === null || ps.length === 0) { e.info.lost = true; return true; }
156
157
  if (!tailIsLeft) ps.reverse();
157
158
  clipAndInstall(e, e.head, ps, ps.length, { ...buildDotSinfo(), ignoreSwap: true });
@@ -34,13 +34,14 @@ import { getSplineBounds, staleAdjacent } from './edge-route-rank.js';
34
34
  import { graphRanksep } from './position-aux.js';
35
35
  import { Edge as EdgeClass } from '../../model/edge.js';
36
36
  import { cloneNode, cloneEdge, cleanupCloneGraph, transformf } from './splines-clone.js';
37
+ import { agsubg } from '../../model/cgraph-ops.js';
37
38
  import { dotInitNodeEdge, AUX_INIT_SYMS } from './init.js';
38
39
  import { gvPostprocess } from '../../common/postproc.js';
39
40
  import { newSpline } from '../../common/splines-clip.js';
40
41
  import { mapArrowOpPoints } from '../../common/arrows-shapes-util.js';
41
42
  import type { ArrowDrawOp } from '../../common/arrows-types.js';
42
43
  import { updateBbBz } from '../../common/splines-geom.js';
43
- import { placeRegularEdgeLabels, updateBB } from './splines-label.js';
44
+ import { updateBB } from './splines-label.js';
44
45
  import { NORMAL, VIRTUAL } from './fastgr.js';
45
46
  import { EDGE_LABEL } from './rank.js';
46
47
 
@@ -110,15 +111,6 @@ export function runAuxSplines(auxg: Graph): number {
110
111
  // @see lib/dotgen/dotsplines.c:make_flat_adj_edges
111
112
  // ---------------------------------------------------------------------------
112
113
 
113
- /**
114
- * Route flat edges between adjacent nodes by running the full dot pipeline
115
- * on a cloned subgraph (rotated 90°).
116
- *
117
- * Acceptance criterion 1: after this call, the cloned graph's nodes have
118
- * coord set (verified by dotPosition setting ND_coord).
119
- *
120
- * @see lib/dotgen/dotsplines.c:make_flat_adj_edges
121
- */
122
114
  /** Aux graph + the two cloned endpoints + original→aux edge map. */
123
115
  interface FlatAux { auxg: Graph; auxt: Node; auxh: Node; alg: Map<Edge, Edge>; }
124
116
 
@@ -165,15 +157,16 @@ function cloneFlatEdge(auxg: Graph, tn: Node, auxt: Node, auxh: Node, orig: Edge
165
157
  * @see lib/dotgen/dotsplines.c:setflags (FLATEDGE order predicate)
166
158
  * @see lib/dotgen/dotsplines.c:make_flat_edge (makefwdedge of *edges)
167
159
  */
168
- function flatLeadPair(edges: Edge[]): { tn: Node; hn: Node } {
160
+ export function flatLeadPair(edges: Edge[]): { tn: Node; hn: Node } {
169
161
  const t = edges[0].tail, h = edges[0].head;
170
162
  return (t.info.order ?? 0) < (h.info.order ?? 0) ? { tn: t, hn: h } : { tn: h, hn: t };
171
163
  }
172
164
 
173
165
  /**
174
- * Build the rotated auxiliary graph: clone tail/head + each edge, then add a
166
+ * Build the rotated auxiliary graph: clone the tail into the `rank=source`
167
+ * subgraph `xxx` and the head into the aux root, clone each edge, then add a
175
168
  * heavy ordering edge so the pair lands on adjacent ranks.
176
- * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (clone + hvye)
169
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges 1177-1185 (subg, clone + hvye)
177
170
  */
178
171
  function buildFlatAux(g: Graph, edges: Edge[], cnt: number): FlatAux {
179
172
  const { tn: ltn, hn: lhn } = flatLeadPair(edges);
@@ -183,7 +176,9 @@ function buildFlatAux(g: Graph, edges: Edge[], cnt: number): FlatAux {
183
176
  // cloned from — so the orientation test in cloneFlatEdge matches C.
184
177
  const refTn = flip ? lhn : ltn;
185
178
  const auxg = cloneGraph(g);
186
- const auxt = cloneNode(auxg, refTn);
179
+ const subg = agsubg(auxg, 'xxx', true)!;
180
+ subg.attrs.set('rank', 'source');
181
+ const auxt = cloneNode(subg, refTn);
187
182
  const auxh = cloneNode(auxg, flip ? ltn : lhn);
188
183
  const alg = new Map<Edge, Edge>();
189
184
  let hvye: Edge | null = null;
@@ -374,11 +369,6 @@ export function makeFlatAdjEdges(g: Graph, edges: Edge[], cnt: number, et: numbe
374
369
  repositionFlatAux(g, edges, aux);
375
370
  dotSameports(aux.auxg);
376
371
  dotSplines_(aux.auxg, false);
377
- // The labeled chain edge routes in routeDotEdges (after dotSplines_'s own
378
- // label pass), so recover_slack repositions the label vnode only afterward.
379
- // Re-place the aux labels here to read the final vnode coords (DOT-12).
380
- // @see lib/dotgen/dotsplines.c:make_regular_edge (recover_slack before place_vnlabel)
381
- placeRegularEdgeLabels(aux.auxg);
382
372
  gvPostprocess(aux.auxg);
383
373
  copyFlatSplines(g, edges, aux);
384
374
  cleanupCloneGraph(aux.auxg);
@@ -115,10 +115,12 @@ function dispatchEdgeGroup(g: Graph, group: Edge[], ctx: GroupRouteCtx): void {
115
115
  const uniq = dedupByOrig(group);
116
116
  // Flat group: route HERE at its edgecmp position, as C's make_flat_edge call
117
117
  // does, so it reads vnodes before later regular edges' recover_slack moves
118
- // them. The flat routers gather their own group and skip routed members.
118
+ // them. Each member carries the run (C's `edges + ind`, `cnt`): the
119
+ // flat-adjacent router takes its group from it, in this order, and the other
120
+ // flat routers gather their own group; all skip routed members.
119
121
  // @see lib/dotgen/dotsplines.c:dot_splines_ (410-411)
120
122
  if (nodeRankOf(e0.tail) === nodeRankOf(e0.head)) {
121
- for (const e of uniq) routeLoneEdge(e, g);
123
+ for (const e of uniq) routeLoneEdge(e, g, uniq);
122
124
  return;
123
125
  }
124
126
  // Lone edge: route HERE at its edgecmp position (interleaved with groups), as C
@@ -139,7 +141,7 @@ function dispatchEdgeGroup(g: Graph, group: Edge[], ctx: GroupRouteCtx): void {
139
141
  const lone = resolveOrigEdge(uniq[0]);
140
142
  // Plain chains (no interior splineMerge boundary) keep the whole-chain
141
143
  // routers. @see dotsplines.c:make_regular_edge (spline_merge)
142
- routeLoneEdge(lone, g);
144
+ routeLoneEdge(lone, g, uniq);
143
145
  return;
144
146
  }
145
147
  // Lane offsets follow the edgecmp collected order — C passes the sorted list