@knowvah/dot-engine 2.12.0 → 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 (166) 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-in-box.d.ts +6 -20
  6. package/dist/common/edge-in-box.d.ts.map +1 -1
  7. package/dist/common/edge-label-init.d.ts +26 -1
  8. package/dist/common/edge-label-init.d.ts.map +1 -1
  9. package/dist/common/emit-bb.d.ts +36 -0
  10. package/dist/common/emit-bb.d.ts.map +1 -0
  11. package/dist/common/nodeinit.d.ts +16 -2
  12. package/dist/common/nodeinit.d.ts.map +1 -1
  13. package/dist/common/splines-path-begin.d.ts.map +1 -1
  14. package/dist/common/splines-path-end.d.ts.map +1 -1
  15. package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts +10 -0
  16. package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts.map +1 -0
  17. package/dist/gvc/context.d.ts +8 -0
  18. package/dist/gvc/context.d.ts.map +1 -1
  19. package/dist/gvc/device.d.ts.map +1 -1
  20. package/dist/gvc/emit-gates.d.ts +5 -10
  21. package/dist/gvc/emit-gates.d.ts.map +1 -1
  22. package/dist/gvc/emit-xdot.d.ts +10 -0
  23. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  24. package/dist/gvc/job.d.ts +5 -2
  25. package/dist/gvc/job.d.ts.map +1 -1
  26. package/dist/gvc/viewport.d.ts +10 -5
  27. package/dist/gvc/viewport.d.ts.map +1 -1
  28. package/dist/index.js +7617 -7334
  29. package/dist/index.js.map +4 -4
  30. package/dist/layout/dot/decomp.d.ts.map +1 -1
  31. package/dist/layout/dot/edge-route.d.ts +10 -11
  32. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  33. package/dist/layout/dot/fastgr.d.ts +5 -3
  34. package/dist/layout/dot/fastgr.d.ts.map +1 -1
  35. package/dist/layout/dot/flat-adj-record.d.ts +22 -0
  36. package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
  37. package/dist/layout/dot/init.d.ts +65 -4
  38. package/dist/layout/dot/init.d.ts.map +1 -1
  39. package/dist/layout/dot/mincross-build.d.ts +6 -0
  40. package/dist/layout/dot/mincross-build.d.ts.map +1 -1
  41. package/dist/layout/dot/position-aux.d.ts +7 -1
  42. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  43. package/dist/layout/dot/splines-clone.d.ts +2 -1
  44. package/dist/layout/dot/splines-clone.d.ts.map +1 -1
  45. package/dist/layout/dot/splines-flat-labeled.d.ts.map +1 -1
  46. package/dist/layout/dot/splines-flat.d.ts +18 -0
  47. package/dist/layout/dot/splines-flat.d.ts.map +1 -1
  48. package/dist/layout/dot/splines-groups.d.ts.map +1 -1
  49. package/dist/layout/dot/splines.d.ts +5 -3
  50. package/dist/layout/dot/splines.d.ts.map +1 -1
  51. package/dist/layout/fdp/ports.d.ts.map +1 -1
  52. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  53. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  54. package/dist/layout/neato/sgd.d.ts.map +1 -1
  55. package/dist/layout/sfdp/spring-electrical.d.ts.map +1 -1
  56. package/dist/model/cgraph-ops.d.ts +10 -2
  57. package/dist/model/cgraph-ops.d.ts.map +1 -1
  58. package/dist/model/edge.d.ts +7 -2
  59. package/dist/model/edge.d.ts.map +1 -1
  60. package/dist/model/edgeInfo.d.ts +17 -2
  61. package/dist/model/edgeInfo.d.ts.map +1 -1
  62. package/dist/model/graph.d.ts +4 -3
  63. package/dist/model/graph.d.ts.map +1 -1
  64. package/dist/model/lazy-attrs.d.ts.map +1 -1
  65. package/dist/parser/builder.d.ts.map +1 -1
  66. package/dist/render/dot/agwrite-linelength.d.ts +25 -0
  67. package/dist/render/dot/agwrite-linelength.d.ts.map +1 -0
  68. package/dist/render/dot/agwrite.d.ts +9 -8
  69. package/dist/render/dot/agwrite.d.ts.map +1 -1
  70. package/dist/render/dot/attrs.d.ts +15 -4
  71. package/dist/render/dot/attrs.d.ts.map +1 -1
  72. package/dist/render/dot/write-back.d.ts +24 -0
  73. package/dist/render/dot/write-back.d.ts.map +1 -1
  74. package/dist/render/dot/xdot-ops.d.ts +20 -29
  75. package/dist/render/dot/xdot-ops.d.ts.map +1 -1
  76. package/dist/render/dot.d.ts +5 -4
  77. package/dist/render/dot.d.ts.map +1 -1
  78. package/dist/render/json-cluster-edge.d.ts +35 -0
  79. package/dist/render/json-cluster-edge.d.ts.map +1 -0
  80. package/dist/render/json-nonfinite.d.ts +17 -0
  81. package/dist/render/json-nonfinite.d.ts.map +1 -0
  82. package/dist/render/json.d.ts +4 -0
  83. package/dist/render/json.d.ts.map +1 -1
  84. package/dist/render/map.d.ts +3 -0
  85. package/dist/render/map.d.ts.map +1 -1
  86. package/dist/render/svg-graph.d.ts.map +1 -1
  87. package/dist/render/svg-id.d.ts +10 -1
  88. package/dist/render/svg-id.d.ts.map +1 -1
  89. package/dist/render/svg.d.ts +3 -1
  90. package/dist/render/svg.d.ts.map +1 -1
  91. package/dist/render.js +7657 -7374
  92. package/dist/render.js.map +4 -4
  93. package/dist/util/bsd-qsort.d.ts.map +1 -1
  94. package/dist/util/printf-round.d.ts.map +1 -1
  95. package/dist/xdot/parse.d.ts.map +1 -1
  96. package/dist/xdot/strtod.d.ts +23 -0
  97. package/dist/xdot/strtod.d.ts.map +1 -0
  98. package/package.json +1 -1
  99. package/src/api/builder.ts +8 -2
  100. package/src/common/edge-in-box.ts +9 -24
  101. package/src/common/edge-label-init.ts +43 -17
  102. package/src/common/emit-bb.ts +128 -0
  103. package/src/common/nodeinit.ts +28 -8
  104. package/src/common/splines-path-begin.ts +4 -3
  105. package/src/common/splines-path-end.ts +4 -3
  106. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +45 -0
  107. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +45 -0
  108. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +45 -0
  109. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +74 -0
  110. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +74 -0
  111. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +76 -0
  112. package/src/gvc/__fixtures__/rerender/nestedclust.gv +4 -0
  113. package/src/gvc/__fixtures__/rerender/regen.sh +5 -0
  114. package/src/gvc/__fixtures__/subg-renders/subg-renders.ts +48 -0
  115. package/src/gvc/context.ts +8 -0
  116. package/src/gvc/device.ts +28 -29
  117. package/src/gvc/emit-gates.ts +7 -16
  118. package/src/gvc/emit-xdot.ts +10 -12
  119. package/src/gvc/job.ts +5 -2
  120. package/src/gvc/viewport.ts +13 -7
  121. package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
  122. package/src/layout/dot/decomp.ts +23 -2
  123. package/src/layout/dot/edge-route.ts +52 -86
  124. package/src/layout/dot/fastgr.ts +9 -3
  125. package/src/layout/dot/flat-adj-record.ts +68 -0
  126. package/src/layout/dot/init.ts +84 -13
  127. package/src/layout/dot/mincross-build.ts +14 -1
  128. package/src/layout/dot/position-aux.ts +10 -3
  129. package/src/layout/dot/splines-clone.ts +8 -2
  130. package/src/layout/dot/splines-flat-labeled.ts +3 -2
  131. package/src/layout/dot/splines-flat.ts +11 -21
  132. package/src/layout/dot/splines-groups.ts +7 -5
  133. package/src/layout/dot/splines-route.ts +2 -2
  134. package/src/layout/dot/splines.ts +8 -8
  135. package/src/layout/fdp/ports.ts +6 -2
  136. package/src/layout/neato/conjgrad-mkernel.ts +6 -2
  137. package/src/layout/neato/conjgrad.ts +2 -2
  138. package/src/layout/neato/fdp-adjust.ts +1 -16
  139. package/src/layout/neato/sgd.ts +2 -1
  140. package/src/layout/sfdp/spring-electrical.ts +5 -3
  141. package/src/model/cgraph-ops.ts +4 -3
  142. package/src/model/edge.ts +11 -4
  143. package/src/model/edgeInfo.ts +18 -2
  144. package/src/model/graph.ts +4 -3
  145. package/src/model/lazy-attrs.ts +3 -1
  146. package/src/parser/builder.ts +12 -3
  147. package/src/render/dot/agwrite-linelength.ts +58 -0
  148. package/src/render/dot/agwrite.ts +23 -16
  149. package/src/render/dot/attrs.ts +45 -8
  150. package/src/render/dot/write-back.ts +48 -3
  151. package/src/render/dot/xdot-ops.ts +26 -57
  152. package/src/render/dot.ts +16 -20
  153. package/src/render/json-cluster-edge.ts +87 -0
  154. package/src/render/json-nonfinite.ts +51 -0
  155. package/src/render/json.ts +36 -42
  156. package/src/render/map.ts +6 -7
  157. package/src/render/svg-graph.ts +9 -8
  158. package/src/render/svg-id.ts +11 -2
  159. package/src/render/svg.ts +7 -4
  160. package/src/util/bsd-qsort.ts +2 -1
  161. package/src/util/printf-round.ts +16 -10
  162. package/src/xdot/parse.ts +9 -19
  163. package/src/xdot/strtod.ts +167 -0
  164. package/dist/layout/dot/edge-order.d.ts +0 -27
  165. package/dist/layout/dot/edge-order.d.ts.map +0 -1
  166. package/src/layout/dot/edge-order.ts +0 -62
@@ -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 { dotInitNodeEdge } from './init.js';
37
+ import { agsubg } from '../../model/cgraph-ops.js';
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;
@@ -367,18 +362,13 @@ export function makeFlatAdjEdges(g: Graph, edges: Edge[], cnt: number, et: numbe
367
362
  // C setEdgeType(auxg, et); inlined (index.ts's setEdgeType would be an import cycle).
368
363
  // @see lib/dotgen/dotsplines.c:make_flat_adj_edges
369
364
  aux.auxg.info.flags = (aux.auxg.info.flags & ~0xf) | (et & 0xf);
370
- dotInitNodeEdge(aux.auxg);
365
+ dotInitNodeEdge(aux.auxg, AUX_INIT_SYMS);
371
366
  dotRank(aux.auxg);
372
367
  if (dotMincross(aux.auxg) !== 0) return 1;
373
368
  if (dotPosition(aux.auxg) !== 0) return 1;
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);
@@ -94,8 +94,8 @@ export function dedupByOrig(group: Edge[]): Edge[] {
94
94
  /**
95
95
  * Dispatch one edgecmp group: self-loop → routeSelfEdgeGroup; cross-rank cnt>1 →
96
96
  * routeParallelEdgeGroup (Multisep offsets); cross-rank cnt==1 → per-run or
97
- * whole-chain lone routing in-place (C order); same-rank flat → left for the
98
- * routeDotEdges sweep.
97
+ * whole-chain lone routing in-place (C order); same-rank flat → routed in place
98
+ * at its edgecmp position.
99
99
  * @see lib/dotgen/dotsplines.c:367-419
100
100
  */
101
101
  function dispatchEdgeGroup(g: Graph, group: Edge[], ctx: GroupRouteCtx): void {
@@ -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
@@ -387,8 +387,8 @@ export function routeParallelEdgeGroup(
387
387
  }) ?? edges[0]!;
388
388
  const base = baseSplineForGroup(g, baseEdge);
389
389
  // A lost group base consumes every member: C's dot_splines_ calls
390
- // make_regular_edge once per group and never re-routes its edges, so the
391
- // routeDotEdges backstop must not re-attempt (and re-report) them.
390
+ // make_regular_edge once per group and never re-routes its edges, so no
391
+ // later group may re-attempt (and re-report) them.
392
392
  // @see lib/dotgen/dotsplines.c:dot_splines_ (group loop, one call per group)
393
393
  if (base === 'lost') {
394
394
  for (const e of edges) resolveOrigEdge(e).info.lost = true;
@@ -19,7 +19,6 @@ import { VIRTUAL, NORMAL, FLATORDER } from './fastgr.js';
19
19
  import { gvQsort } from '../../util/bsd-qsort.js';
20
20
  import { IGNORED, EDGE_LABEL } from './rank.js';
21
21
  import { markLowclusters } from './cluster.js';
22
- import { routeDotEdges } from './edge-route.js';
23
22
  import { collectOtherEdges } from './self-loop.js';
24
23
  import { beginRoutingPass, staleBezierCount, swapStaleBeziers } from './edge-route-rank.js';
25
24
  import { dispatchOrthoEdges } from './ortho-adapter.js';
@@ -417,9 +416,11 @@ export function collectRankEdges(g: Graph, edges: Edge[]): void {
417
416
  /**
418
417
  * Main spline routing entry point (internal, with normalize flag).
419
418
  *
420
- * Performs straight-line edge routing via routeDotEdges, then normalizes
421
- * spline orientation when normalize=true. The full pathplan-based obstacle
422
- * routing (routesplines, boxes, clip_and_install) is deferred.
419
+ * Routes the edges collected from the rank arrays, group by group in
420
+ * `edgecmp` order, then normalizes spline orientation when normalize=true. An
421
+ * edge that is not in the rank arrays is not routed and keeps whatever route
422
+ * it already had: a layout with no free between it and the last one appends
423
+ * nothing to such an edge's spline, as `new_spline` is never called for it.
423
424
  *
424
425
  * @see lib/dotgen/dotsplines.c:dot_splines_
425
426
  */
@@ -481,12 +482,11 @@ function curvedTop(g: Graph): void {
481
482
  }
482
483
 
483
484
  /**
484
- * Post-loop: labels, normalize, backstop (curved skips it), port labels. @see c:422-471
485
+ * Post-loop: labels, normalize, port labels. @see c:422-471
485
486
  */
486
- function finalizeSplines(g: Graph, et: number, normalize: boolean): void {
487
+ function finalizeSplines(g: Graph, normalize: boolean): void {
487
488
  placeRegularEdgeLabels(g);
488
489
  if (normalize) edgeNormalize(g);
489
- if (et !== EDGETYPE_CURVED) routeDotEdges(g);
490
490
  if (normalize) swapStaleBeziers(g);
491
491
  placePortLabels(g);
492
492
  setState(GVSPLINES); // @see dotsplines.c:477
@@ -520,7 +520,7 @@ export function dotSplines_(g: Graph, normalize: boolean): number {
520
520
  if (et === EDGETYPE_LINE) placeRegularEdgeLabels(g);
521
521
  const runOrigs = routeEdgeGroups(g, edges, g.info.nodesep ?? 18, et);
522
522
  if (normalize) normalizeRunOrigs(runOrigs);
523
- finalizeSplines(g, et, normalize);
523
+ finalizeSplines(g, normalize);
524
524
  return 0;
525
525
  }
526
526
 
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { InternalError } from '../../errors.js';
15
+ import { fma } from '../../common/fma.js';
15
16
  import type { Graph } from '../../model/graph.js';
16
17
  import type { Node } from '../../model/node.js';
17
18
  import type { Edge } from '../../model/edge.js';
@@ -76,7 +77,8 @@ export function getEdgeList(n: Node, g: Graph): Erec[] {
76
77
  const m = e.head === n ? e.tail : e.head;
77
78
  const dx = m.info.pos![0]! - n.info.pos![0]!;
78
79
  const dy = m.info.pos![1]! - n.info.pos![1]!;
79
- erecs.push({ e, alpha: Math.atan2(dy, dx), dist2: dx * dx + dy * dy });
80
+ // contracted (-ffp-contract=on): fmadd of the first product
81
+ erecs.push({ e, alpha: Math.atan2(dy, dx), dist2: fma(dx, dx, dy * dy) });
80
82
  }
81
83
  if (erecs.length !== deg) {
82
84
  throw new InternalError(`fdp getEdgeList: ${erecs.length} edges vs deg ${deg}`);
@@ -107,7 +109,9 @@ export function genPorts(
107
109
  const fwd = n.id < other.id;
108
110
  const fan = fwd
109
111
  ? { i: idx, inc: 1, angle: er.alpha, delta }
110
- : { i: idx + cnt - 1, inc: -1, angle: er.alpha + delta * (cnt - 1), delta: -delta };
112
+ : { // contracted (-ffp-contract=on): angle += delta * (cnt - 1) is one fmadd
113
+ i: idx + cnt - 1, inc: -1, angle: fma(delta, cnt - 1, er.alpha), delta: -delta,
114
+ };
111
115
 
112
116
  fillPorts(n, e, pp, fan);
113
117
  return idx + cnt;
@@ -24,8 +24,12 @@ const fr = Math.fround;
24
24
  /** Width of the vectorised reduction block of `right_mult_with_vector_ff`. */
25
25
  const RIGHT_MULT_BLOCK = 16;
26
26
 
27
- /** The unexpected-zero-residual diagnostic. @see lib/neatogen/conjgrad.c */
28
- const ZERO_LENGTH_MESSAGE = 'conjugate_gradient: unexpected length 0 vector\n';
27
+ /**
28
+ * The unexpected-zero-residual diagnostic, without C's trailing `\n`: the
29
+ * port's agerr writers finish the line themselves (`common/agerr.ts`).
30
+ * @see lib/neatogen/conjgrad.c:65
31
+ */
32
+ const ZERO_LENGTH_MESSAGE = 'conjugate_gradient: unexpected length 0 vector';
29
33
 
30
34
  /**
31
35
  * `result = packed_matrix * vector` for the packed upper triangle of a
@@ -206,7 +206,7 @@ function cgNextDirection(n: number, w: CgWork, alpha: number, rR: number): numbe
206
206
  vectorsSubtraction(n, w.r, w.Ap, w.r); // fast computation of r, the residual
207
207
  const rRNew = innerProduct(n, w.r, w.r, BLOCK_NONE);
208
208
  if (rR === 0) {
209
- agerrorf('conjugate_gradient: unexpected length 0 vector\n');
209
+ agerrorf('conjugate_gradient: unexpected length 0 vector');
210
210
  return null;
211
211
  }
212
212
  const beta = rRNew / rR;
@@ -323,7 +323,7 @@ function cgfUpdate(n: number, alpha: number, st: CgfState): number {
323
323
  vectorsSubtraction(n, st.r, st.Ap, st.r);
324
324
  const rrNew = innerProduct(n, st.r, st.r, BLOCK_NONE);
325
325
  if (st.rr === 0) {
326
- agerrorf('conjugate_gradient: unexpected length 0 vector\n');
326
+ agerrorf('conjugate_gradient: unexpected length 0 vector');
327
327
  return 1;
328
328
  }
329
329
  const beta = rrNew / st.rr;
@@ -32,21 +32,6 @@ import { agwarningf } from '../../common/agerr.js';
32
32
  /** @see lib/neatogen/adjust.c:DFLT_MARGIN (points) */
33
33
  const DFLT_MARGIN = 4;
34
34
 
35
- /**
36
- * getSizes lays `sizes` out Ndim apart (x, y, then zeros); sfdp's getSizes
37
- * returns the 2-wide layout, so widen it to `ndim`.
38
- * @see lib/neatogen/adjust.c:getSizes
39
- */
40
- function sizesByNdim(sizes2: number[], ndim: number): number[] {
41
- if (ndim === 2) return sizes2;
42
- const sizes = new Array<number>((sizes2.length / 2) * ndim).fill(0);
43
- for (let i = 0; i < sizes2.length / 2; i++) {
44
- sizes[i * ndim] = sizes2[i * 2]!;
45
- sizes[i * ndim + 1] = sizes2[i * 2 + 1]!;
46
- }
47
- return sizes;
48
- }
49
-
50
35
  /** @see lib/common/utils.c:mapBool */
51
36
  function mapBoolDflt(p: string | undefined, defaultValue: boolean): boolean {
52
37
  if (p === undefined || p === '') return defaultValue;
@@ -102,7 +87,7 @@ export function fdpAdjust(g: Graph, ntry: number): void {
102
87
  const pad = sep.doAdd
103
88
  ? { x: sep.x / 72, y: sep.y / 72 }
104
89
  : { x: DFLT_MARGIN / 72, y: DFLT_MARGIN / 72 };
105
- const sizes = sizesByNdim(getSizes(g, pad), ndim);
90
+ const sizes = getSizes(g, pad, ndim);
106
91
 
107
92
  for (const n of g.nodes.values()) {
108
93
  const i = n.info.id!;
@@ -15,6 +15,7 @@ import { setEdgeLen } from './edge-len.js';
15
15
  import { rkNewState, rkSeed, rkInterval } from '../../util/mt19937.js';
16
16
  import type { RkState } from '../../util/mt19937.js';
17
17
  import { drand48 } from '../../common/random.js';
18
+ import { libmHypot } from '../../common/libm-hypot.js';
18
19
  import { lateDouble } from '../../common/nodeinit.js';
19
20
  import { checkStart, parseStart, INIT_RANDOM, INIT_REGULAR } from './start.js';
20
21
  import { jitter3d, ndimOf } from './init-dim.js';
@@ -343,7 +344,7 @@ export function sgdIteration(
343
344
  const mu = Math.min(eta * t.w, 1);
344
345
  const dx = pos[2 * t.i] - pos[2 * t.j];
345
346
  const dy = pos[2 * t.i + 1] - pos[2 * t.j + 1];
346
- const mag = Math.hypot(dx, dy);
347
+ const mag = libmHypot(dx, dy);
347
348
  if (mag === 0) continue;
348
349
  const r = (mu * (mag - t.d)) / (2 * mag);
349
350
  const rx = r * dx;
@@ -9,9 +9,11 @@
9
9
  * _spring_electrical_embedding), the attractive update to
10
10
  * `fnmul`+`fmadd` (the CRK·Δ product is rounded, then fused with
11
11
  * dist), and the position update to fmadd. The repulsive pow() is a
12
- * REAL libm call in the binary (runtime exponent) — reproduced by the
13
- * bit-exact Apple pow port in src/common/apple-pow.ts (its ~0.5-ULP
14
- * roundings flip adaptive-cooling branches if approximated).
12
+ * REAL libm call in the binary (runtime exponent); this port calls
13
+ * `armPow` (src/common/arm-pow.ts). Its last bit can differ from the
14
+ * platform's `pow`, which flips adaptive-cooling branches; that drift is
15
+ * accepted (user decision, PR 119; `.agent-notes/post-16-1-followups-10.md`,
16
+ * "sfdp's drift is the repulsive pow's last bit").
15
17
  *
16
18
  * The slow (QUAD_TREE_NONE) and fast (QUAD_TREE_FAST/large-HYBRID)
17
19
  * embedding variants are unreachable at sfdp defaults and not ported.
@@ -24,7 +24,7 @@ import { Node } from './node.js';
24
24
  * @see lib/cgraph/cghdr.h:LOCALNAMEPREFIX
25
25
  * @see lib/cgraph/id.c:aginternalmapprint
26
26
  */
27
- const LOCALNAMEPREFIX = '%';
27
+ export const LOCALNAMEPREFIX = '%';
28
28
 
29
29
  /**
30
30
  * cgraph's id for the first anonymous object, which an anonymous root graph is
@@ -37,8 +37,9 @@ const ANONYMOUS_ROOT_ID = 1;
37
37
  * Graph name as `agnameof` returns it: the DOT name, or `%<id>` for an
38
38
  * anonymous graph. The port stores `''` for an anonymous root (dot/xdot
39
39
  * re-serialization must not print the `%` name), so it is restored here.
40
- * Anonymous subgraph ids are not tracked; callers pass the root, as C's
41
- * neato message sites do.
40
+ * An anonymous subgraph already carries its `%N` name (the parser allocates
41
+ * it), so only the root needs restoring; the dot writer passes either, and
42
+ * the neato message sites pass the root, as C's do.
42
43
  * @see lib/cgraph/id.c:agnameof
43
44
  */
44
45
  export function agNameOf(g: Graph): string {
package/src/model/edge.ts CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { Node } from './node.js';
11
11
  import { EMPTY_ATTRS } from './lazy-attrs.js';
12
- import { type EdgeInfo, makeEdgeInfo, makePort } from './edgeInfo.js';
12
+ import { type EdgeInfo, AUX_EDGE_PORT, makeEdgeInfo, makePort } from './edgeInfo.js';
13
13
 
14
14
  /**
15
15
  * Represents an abstract edge in the graph, corresponding to Agedgepair_t.
@@ -93,13 +93,20 @@ export class Edge {
93
93
  */
94
94
  info: EdgeInfo;
95
95
 
96
- /** @see lib/cgraph/edge.c:agedge */
97
- constructor(tail: Node, head: Node, name: string, lazyAttrs = false) {
96
+ /**
97
+ * `auxPorts` is for dot's auxiliary edges only: both ends take the shared
98
+ * {@link AUX_EDGE_PORT} in place of a private port each.
99
+ * @see lib/cgraph/edge.c:agedge
100
+ * @see lib/dotgen/position.c:make_aux_edge
101
+ */
102
+ constructor(tail: Node, head: Node, name: string, lazyAttrs = false, auxPorts = false) {
98
103
  this.seq = Edge._nextSeq++;
99
104
  this.tail = tail;
100
105
  this.head = head;
101
106
  this.name = name;
102
107
  this.attrs = lazyAttrs ? EMPTY_ATTRS : new Map();
103
- this.info = makeEdgeInfo(makePort(), makePort());
108
+ this.info = auxPorts
109
+ ? makeEdgeInfo(AUX_EDGE_PORT, AUX_EDGE_PORT)
110
+ : makeEdgeInfo(makePort(), makePort());
104
111
  }
105
112
  }
@@ -173,8 +173,9 @@ export interface EdgeInfo {
173
173
 
174
174
  /**
175
175
  * Routing attempted and routesplines failed: the edge is LOST exactly as in
176
- * C (no spline installed, map_edge warns, emit skips). Port-only bookkeeping
177
- * so the routeDotEdges backstop does not re-attempt an edge C routes once.
176
+ * C (no spline installed, map_edge warns, emit skips). Port-only bookkeeping:
177
+ * routeLoneEdge skips a lost edge, so a later call in the same routing pass
178
+ * does not re-attempt an edge C routes once; beginRoutingPass clears it.
178
179
  * @see lib/common/routespl.c:routesplines (NULL), lib/common/postproc.c:map_edge
179
180
  */
180
181
  lost?: boolean;
@@ -391,6 +392,21 @@ export function makePort(): Port {
391
392
  };
392
393
  }
393
394
 
395
+ /**
396
+ * The default port both ends of every auxiliary edge share.
397
+ *
398
+ * C's make_aux_edge zero-allocates one Agedgeinfo_t, so an aux edge's
399
+ * ED_tail_port and ED_head_port are two structs inside that block, and nothing
400
+ * writes them before remove_aux_edges frees the edge. A makePort() pair per aux
401
+ * edge stood for those 96 inline bytes with 352 B of separate objects (two
402
+ * ports, two points, four boxed doubles), on a structure separate_subclust
403
+ * builds once per pair of sibling clusters (16.3 M on tests/2475_1.dot). It
404
+ * carries makePort()'s values and is frozen with its point, so a write throws
405
+ * rather than reaching every aux edge.
406
+ * @see lib/dotgen/position.c:make_aux_edge
407
+ */
408
+ export const AUX_EDGE_PORT: Port = Object.freeze({ ...makePort(), p: Object.freeze({ x: 0, y: 0 }) });
409
+
394
410
  /**
395
411
  * Constructs a minimal EdgeInfo with required port fields initialized.
396
412
  *
@@ -48,9 +48,10 @@ export class Graph {
48
48
  * True when the graph was declared with NO name (`digraph {`), as opposed to
49
49
  * an explicit empty name (`digraph "" {`). Both store `name === ''`, but
50
50
  * cgraph gives the truly-anonymous root the internal id `%1` (agnameof) while
51
- * the empty-named one keeps `""`. Only the imagemap `<map id/name>` reads this
52
- * (map.ts:mapGraphName); dot/xdot re-serialization keeps `name` so an
53
- * anonymous root round-trips as `digraph {`, not `digraph %1 {`.
51
+ * the empty-named one keeps `""`. Read through `agNameOf` by the imagemap
52
+ * `<map id/name>`, the neato messages and the dot/xdot writer's header,
53
+ * which prints `digraph {` for an anonymous root and `digraph "" {` for the
54
+ * empty-named one. `name` stays `''` for both.
54
55
  * @see lib/cgraph/id.c:idmap (anon → `%1`) ; lib/cgraph/agraph.c:agnameof
55
56
  */
56
57
  readonly anonymous: boolean;
@@ -1,7 +1,8 @@
1
1
  // SPDX-License-Identifier: EPL-2.0
2
2
 
3
3
  /**
4
- * Shared empty attribute map for dot virtual nodes/edges (AD-12).
4
+ * Shared empty attribute map for dot virtual nodes/edges (AD-12) and for
5
+ * auxiliary edges (make_aux_edge, issue #145).
5
6
  *
6
7
  * C virtual nodes/edges carry no attribute record; allocating an empty `Map`
7
8
  * per object cost ~372 B per virtual pair. Virtual objects start with this
@@ -9,6 +10,7 @@
9
10
  * through {@link ownAttrs}, which materialises a private `Map`. A direct
10
11
  * mutation of the shared map throws rather than leaking into every virtual.
11
12
  * @see lib/dotgen/fastgr.c:virtual_node
13
+ * @see lib/dotgen/position.c:make_aux_edge
12
14
  */
13
15
 
14
16
  class SharedEmptyAttrs extends Map<string, string> {
@@ -10,6 +10,7 @@ import { Graph, type GraphKind } from '../model/graph.js';
10
10
  import { Node } from '../model/node.js';
11
11
  import { Edge } from '../model/edge.js';
12
12
  import { assignSubgSeq } from '../model/cgraph-ops.js';
13
+ import { htmlValueContent, isHtmlValue } from '../common/html-string.js';
13
14
  import type {
14
15
  AttrPair,
15
16
  NodeId,
@@ -475,12 +476,20 @@ export function buildFromAst(ast: ParsedGraph): Graph {
475
476
  else kind = 'undirected';
476
477
  // ast.id is null for a nameless root (`digraph {`) and '' for an explicit
477
478
  // empty name (`digraph "" {`); only the former is anonymous in cgraph (→ `%1`).
478
- const graph = new Graph(ast.id ?? '', kind, ast.id == null);
479
+ // An html-like root name (`digraph <h g> {`) is plain text: the lexer interns
480
+ // it with agstrdup_html before the graph exists, so agopen's idmap finds no
481
+ // html ref in the new graph's dictionary and copies it as text. Node and
482
+ // subgraph names are interned in the graph and keep the flag.
483
+ // @see lib/cgraph/scan.l:233, lib/cgraph/id.c:52, lib/cgraph/refstr.c:agstrdup
484
+ const id = ast.id ?? '';
485
+ const graph = new Graph(isHtmlValue(id) ? htmlValueContent(id) : id, kind, ast.id == null);
479
486
  // An unnamed root graph is itself anonymous in cgraph (agopen with no name),
480
487
  // consuming anon id 1 before any statement — so the first anonymous subgraph is
481
- // %3, not %1 (a named root leaves the counter at 0 → first subgraph %1).
488
+ // %3, not %1 (a named root leaves the counter at 0 → first subgraph %1). A root
489
+ // named `""` is named: idmap maps the string and leaves the counter alone, so
490
+ // the test is for null, not for a falsy id.
482
491
  // @see lib/cgraph/graph.c:agopen, lib/cgraph/id.c:idmap
483
- if (!ast.id) processor.advanceAnonId();
492
+ if (ast.id == null) processor.advanceAnonId();
484
493
  buildGraph(ast.stmts, graph, graph, ast.directed, processor);
485
494
  return graph;
486
495
  }
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * agwrite's `linelength` handling: the root's `linelength` sets C's static
5
+ * `Max_outputline` for the duration of one write, and 128 is restored after.
6
+ *
7
+ * @see lib/cgraph/write.c:agwrite (670-677, 692)
8
+ */
9
+
10
+ import type { Graph } from '../../model/graph.js';
11
+
12
+ /** Default line-break threshold. @see lib/cgraph/write.c:MAX_OUTPUTLINE */
13
+ export const MAX_OUTPUTLINE = 128;
14
+
15
+ /** Smallest nonzero `linelength` agwrite accepts. @see lib/cgraph/write.c:MIN_OUTPUTLINE */
16
+ export const MIN_OUTPUTLINE = 60;
17
+
18
+ /** C's static `Max_outputline` (write.c): agwrite sets it from the root's
19
+ * `linelength` and restores {@link MAX_OUTPUTLINE} after, so the plain path
20
+ * (direct agstrcanon, no agwrite) observes the default. 0 disables breaking.
21
+ * Single-threaded, set and restored synchronously around one serialize.
22
+ * @see lib/cgraph/write.c:44,676,692 */
23
+ let maxOutputlineValue = MAX_OUTPUTLINE;
24
+
25
+ /** `Max_outputline`, as `_write_canonstr` reads it. @see lib/cgraph/write.c:_write_canonstr */
26
+ export function maxOutputline(): number { return maxOutputlineValue; }
27
+
28
+ /** Set `Max_outputline`. @see lib/cgraph/write.c:agwrite */
29
+ function setMaxOutputline(n: number): void { maxOutputlineValue = n; }
30
+
31
+ /** `INT_MAX`, the upper bound agwrite accepts for `linelength`. */
32
+ const INT_MAX = 2147483647;
33
+
34
+ /**
35
+ * The `Max_outputline` agwrite would set for `s` (the root's `linelength`), or
36
+ * `undefined` when C leaves it unchanged: C needs a leading digit, then
37
+ * `strtoul` (which stops at the first non-digit), and accepts 0 or
38
+ * ≥ MIN_OUTPUTLINE up to INT_MAX.
39
+ * @see lib/cgraph/write.c:agwrite (670-677)
40
+ */
41
+ export function linelengthOf(s: string | undefined): number | undefined {
42
+ if (s === undefined || !/^[0-9]/.test(s)) return undefined;
43
+ const len = Number(/^[0-9]+/.exec(s)![0]);
44
+ if ((len === 0 || len >= MIN_OUTPUTLINE) && len <= INT_MAX) return len;
45
+ return undefined;
46
+ }
47
+
48
+ /** Run `write` with `Max_outputline` set from `g`'s `linelength`, restoring 128
49
+ * after. @see lib/cgraph/write.c:agwrite */
50
+ export function withLinelength(g: Graph, write: () => string): string {
51
+ const len = linelengthOf(g.attrs.get('linelength'));
52
+ if (len !== undefined) setMaxOutputline(len);
53
+ try {
54
+ return write();
55
+ } finally {
56
+ setMaxOutputline(MAX_OUTPUTLINE);
57
+ }
58
+ }