@knowvah/dot-engine 2.12.2 → 2.12.4

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 (262) hide show
  1. package/dist/api.js +12 -2
  2. package/dist/api.js.map +2 -2
  3. package/dist/common/clust-map.d.ts +16 -0
  4. package/dist/common/clust-map.d.ts.map +1 -0
  5. package/dist/common/compass-port.d.ts.map +1 -1
  6. package/dist/common/graph-init.d.ts.map +1 -1
  7. package/dist/common/htmltable-emit.d.ts +9 -6
  8. package/dist/common/htmltable-emit.d.ts.map +1 -1
  9. package/dist/common/htmltable-label.d.ts.map +1 -1
  10. package/dist/common/htmltable-lex.d.ts +3 -1
  11. package/dist/common/htmltable-lex.d.ts.map +1 -1
  12. package/dist/common/htmltable-parse-image.d.ts +23 -0
  13. package/dist/common/htmltable-parse-image.d.ts.map +1 -0
  14. package/dist/common/htmltable-parse-state.d.ts +4 -0
  15. package/dist/common/htmltable-parse-state.d.ts.map +1 -1
  16. package/dist/common/htmltable-parse.d.ts +33 -2
  17. package/dist/common/htmltable-parse.d.ts.map +1 -1
  18. package/dist/common/layers.d.ts +9 -0
  19. package/dist/common/layers.d.ts.map +1 -1
  20. package/dist/common/poly-gencode.d.ts.map +1 -1
  21. package/dist/common/poly-inside.d.ts.map +1 -1
  22. package/dist/common/splines-geom.d.ts +2 -1
  23. package/dist/common/splines-geom.d.ts.map +1 -1
  24. package/dist/common/splines-routespl.d.ts +3 -0
  25. package/dist/common/splines-routespl.d.ts.map +1 -1
  26. package/dist/common/xlabels-place.d.ts.map +1 -1
  27. package/dist/gvc/anchor.d.ts +17 -19
  28. package/dist/gvc/anchor.d.ts.map +1 -1
  29. package/dist/gvc/device-cluster.d.ts +9 -0
  30. package/dist/gvc/device-cluster.d.ts.map +1 -1
  31. package/dist/gvc/device.d.ts +2 -1
  32. package/dist/gvc/device.d.ts.map +1 -1
  33. package/dist/gvc/emit-walk.d.ts +7 -0
  34. package/dist/gvc/emit-walk.d.ts.map +1 -1
  35. package/dist/gvc/job.d.ts +13 -6
  36. package/dist/gvc/job.d.ts.map +1 -1
  37. package/dist/gvc/viewport.d.ts +14 -0
  38. package/dist/gvc/viewport.d.ts.map +1 -1
  39. package/dist/index.js +21767 -21607
  40. package/dist/index.js.map +4 -4
  41. package/dist/layout/dot/classify.d.ts.map +1 -1
  42. package/dist/layout/dot/compound.d.ts +0 -4
  43. package/dist/layout/dot/compound.d.ts.map +1 -1
  44. package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
  45. package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
  46. package/dist/layout/dot/edge-route-chain.d.ts +20 -16
  47. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  48. package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
  49. package/dist/layout/dot/flat.d.ts +22 -7
  50. package/dist/layout/dot/flat.d.ts.map +1 -1
  51. package/dist/layout/dot/mincross-flat.d.ts +10 -1
  52. package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
  53. package/dist/layout/dot/mincross.d.ts +6 -1
  54. package/dist/layout/dot/mincross.d.ts.map +1 -1
  55. package/dist/layout/dot/ns-subtree.d.ts +9 -6
  56. package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
  57. package/dist/layout/dot/pack-components.d.ts +4 -3
  58. package/dist/layout/dot/pack-components.d.ts.map +1 -1
  59. package/dist/layout/dot/position-aux.d.ts +62 -20
  60. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  61. package/dist/layout/dot/position-bbox.d.ts.map +1 -1
  62. package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
  63. package/dist/layout/dot/position.d.ts.map +1 -1
  64. package/dist/layout/dot/rank-dot2.d.ts +7 -25
  65. package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
  66. package/dist/layout/dot/self-loop.d.ts +11 -4
  67. package/dist/layout/dot/self-loop.d.ts.map +1 -1
  68. package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
  69. package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
  70. package/dist/layout/dot/splines-route.d.ts +6 -3
  71. package/dist/layout/dot/splines-route.d.ts.map +1 -1
  72. package/dist/layout/dot/straight-edges.d.ts.map +1 -1
  73. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  74. package/dist/layout/fdp/tlayout.d.ts +3 -0
  75. package/dist/layout/fdp/tlayout.d.ts.map +1 -1
  76. package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
  77. package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
  78. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
  79. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
  80. package/dist/layout/neato/conjgrad.d.ts +7 -6
  81. package/dist/layout/neato/conjgrad.d.ts.map +1 -1
  82. package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
  83. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
  84. package/dist/layout/neato/matrix-ops.d.ts +0 -6
  85. package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
  86. package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
  87. package/dist/model/cgraph-ops.d.ts +7 -0
  88. package/dist/model/cgraph-ops.d.ts.map +1 -1
  89. package/dist/model/graph.d.ts +12 -2
  90. package/dist/model/graph.d.ts.map +1 -1
  91. package/dist/model/rankEntry.d.ts +3 -1
  92. package/dist/model/rankEntry.d.ts.map +1 -1
  93. package/dist/ortho/index.d.ts +0 -1
  94. package/dist/ortho/index.d.ts.map +1 -1
  95. package/dist/ortho/partition.d.ts +2 -4
  96. package/dist/ortho/partition.d.ts.map +1 -1
  97. package/dist/parser/builder.d.ts +11 -10
  98. package/dist/parser/builder.d.ts.map +1 -1
  99. package/dist/parser/graph-attr-syms.d.ts +35 -0
  100. package/dist/parser/graph-attr-syms.d.ts.map +1 -0
  101. package/dist/pathplan/route.d.ts +93 -0
  102. package/dist/pathplan/route.d.ts.map +1 -1
  103. package/dist/render/dot/agwrite.d.ts +27 -16
  104. package/dist/render/dot/agwrite.d.ts.map +1 -1
  105. package/dist/render/dot/attrs.d.ts +5 -0
  106. package/dist/render/dot/attrs.d.ts.map +1 -1
  107. package/dist/render/dot/types.d.ts +7 -2
  108. package/dist/render/dot/types.d.ts.map +1 -1
  109. package/dist/render/json-cluster-edge.d.ts +3 -2
  110. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  111. package/dist/render/json.d.ts +7 -1
  112. package/dist/render/json.d.ts.map +1 -1
  113. package/dist/render/map.d.ts +14 -10
  114. package/dist/render/map.d.ts.map +1 -1
  115. package/dist/render/svg-graph.d.ts.map +1 -1
  116. package/dist/render/svg-id.d.ts +9 -0
  117. package/dist/render/svg-id.d.ts.map +1 -1
  118. package/dist/render.js +22009 -21849
  119. package/dist/render.js.map +4 -4
  120. package/dist/util/overflow.d.ts +37 -0
  121. package/dist/util/overflow.d.ts.map +1 -0
  122. package/dist/util/printf-round.d.ts +8 -0
  123. package/dist/util/printf-round.d.ts.map +1 -1
  124. package/package.json +3 -2
  125. package/src/common/clust-map.ts +58 -0
  126. package/src/common/compass-port.ts +36 -20
  127. package/src/common/graph-init.ts +11 -1
  128. package/src/common/htmltable-emit.ts +87 -7
  129. package/src/common/htmltable-label.ts +9 -4
  130. package/src/common/htmltable-lex.ts +5 -2
  131. package/src/common/htmltable-parse-image.ts +69 -0
  132. package/src/common/htmltable-parse-state.ts +6 -0
  133. package/src/common/htmltable-parse.ts +34 -44
  134. package/src/common/layers.ts +25 -4
  135. package/src/common/poly-gencode.ts +3 -11
  136. package/src/common/poly-inside.ts +11 -5
  137. package/src/common/splines-geom.ts +24 -6
  138. package/src/common/splines-routespl.ts +32 -0
  139. package/src/common/xlabels-place.ts +22 -4
  140. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
  141. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
  142. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
  143. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
  144. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
  145. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
  146. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
  147. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
  148. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
  149. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
  150. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
  151. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
  152. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
  153. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
  154. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
  155. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
  156. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
  157. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
  158. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
  159. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
  160. package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
  161. package/src/gvc/anchor.ts +18 -30
  162. package/src/gvc/device-cluster.ts +16 -0
  163. package/src/gvc/device.ts +20 -20
  164. package/src/gvc/emit-walk.ts +11 -1
  165. package/src/gvc/job.ts +17 -9
  166. package/src/gvc/viewport.ts +27 -6
  167. package/src/layout/dot/classify.ts +5 -2
  168. package/src/layout/dot/compound.ts +1 -21
  169. package/src/layout/dot/edge-route-chain-views.ts +120 -0
  170. package/src/layout/dot/edge-route-chain.ts +103 -117
  171. package/src/layout/dot/edge-route-faithful.ts +20 -5
  172. package/src/layout/dot/flat.ts +38 -17
  173. package/src/layout/dot/mincross-flat.ts +15 -5
  174. package/src/layout/dot/mincross.ts +6 -2
  175. package/src/layout/dot/ns-subtree.ts +11 -7
  176. package/src/layout/dot/pack-components.ts +6 -4
  177. package/src/layout/dot/position-aux.ts +112 -39
  178. package/src/layout/dot/position-bbox.ts +14 -1
  179. package/src/layout/dot/position-ycoords.ts +7 -1
  180. package/src/layout/dot/position.ts +4 -1
  181. package/src/layout/dot/rank-dot2.ts +13 -94
  182. package/src/layout/dot/self-loop.ts +29 -11
  183. package/src/layout/dot/splines-flat-multi.ts +12 -4
  184. package/src/layout/dot/splines-route.ts +10 -11
  185. package/src/layout/dot/straight-edges.ts +5 -3
  186. package/src/layout/fdp/cluster-edges.ts +2 -23
  187. package/src/layout/fdp/tlayout.ts +6 -5
  188. package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
  189. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
  190. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
  191. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
  192. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
  193. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
  194. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
  195. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
  196. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
  197. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
  198. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
  199. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
  200. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
  201. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
  202. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
  203. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
  204. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
  205. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
  206. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
  207. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
  208. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
  209. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
  210. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
  211. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
  212. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
  213. package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
  214. package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
  215. package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
  216. package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
  217. package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
  218. package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
  219. package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
  220. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
  221. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
  222. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
  223. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
  224. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
  225. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
  226. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
  227. package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
  228. package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
  229. package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
  230. package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
  231. package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
  232. package/src/layout/neato/conjgrad.ts +38 -35
  233. package/src/layout/neato/matrix-ops-dense.ts +2 -20
  234. package/src/layout/neato/matrix-ops.ts +0 -20
  235. package/src/layout/neato/quad-prog-vpsc.ts +7 -5
  236. package/src/layout/neato/smart-ini-x.ts +15 -15
  237. package/src/layout/neato/stress-subspace.ts +5 -5
  238. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
  239. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
  240. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
  241. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
  242. package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
  243. package/src/model/cgraph-ops.ts +12 -0
  244. package/src/model/graph.ts +13 -2
  245. package/src/model/rankEntry.ts +3 -1
  246. package/src/ortho/index.ts +0 -1
  247. package/src/ortho/partition.ts +10 -22
  248. package/src/parser/builder.ts +67 -100
  249. package/src/parser/graph-attr-syms.ts +62 -0
  250. package/src/pathplan/route.ts +14 -4
  251. package/src/render/dot/agwrite.ts +47 -27
  252. package/src/render/dot/attrs.ts +6 -2
  253. package/src/render/dot/types.ts +7 -2
  254. package/src/render/json-cluster-edge.ts +8 -4
  255. package/src/render/json.ts +15 -8
  256. package/src/render/map.ts +49 -58
  257. package/src/render/svg-cluster.ts +3 -3
  258. package/src/render/svg-graph.ts +1 -3
  259. package/src/render/svg-helpers.ts +6 -6
  260. package/src/render/svg-id.ts +23 -5
  261. package/src/util/overflow.ts +74 -0
  262. package/src/util/printf-round.ts +11 -0
@@ -108,8 +108,8 @@ export class Graph {
108
108
 
109
109
  /**
110
110
  * Keys in `attrs` the BUILDER seeded from `graphDefaultsSnapshot` rather than
111
- * the input declaring them in this scope (see builder.ts GRAPH_LABEL_INHERIT_
112
- * KEYS). cgraph distinguishes these structurally — a seeded value is inherited
111
+ * the input declaring them in this scope: every key of the snapshot the
112
+ * scope did not set (agmakeattrs). cgraph distinguishes these structurally — a seeded value is inherited
113
113
  * through the dict view and has no local symbol, while a local declaration
114
114
  * creates one even when its value equals the inherited value — so the
115
115
  * serializer needs the provenance to decide what write_dict would print.
@@ -118,6 +118,17 @@ export class Graph {
118
118
  */
119
119
  seededAttrs?: Set<string>;
120
120
 
121
+ /**
122
+ * Graph-attribute keys this subgraph holds a local symbol for without having
123
+ * declared them: `unviewsubgraphsattr` gives each direct subgraph one, with
124
+ * its current value, when the parent updates its own symbol. The value is
125
+ * the `attrs` entry (absent for the empty default). A subgraph opened in
126
+ * this one later copies that value, not a nearer ancestor's newer one.
127
+ * Undefined on the root and on a subgraph that was never pinned.
128
+ * @see lib/cgraph/attr.c:232 unviewsubgraphsattr
129
+ */
130
+ pinnedAttrs?: Set<string>;
131
+
121
132
  /**
122
133
  * Graph-attribute keys whose declaration in THIS scope was the first anywhere
123
134
  * in the graph. cgraph's `setattr` splits on exactly this: a key with no
@@ -73,8 +73,10 @@ export interface RankEntry {
73
73
 
74
74
  /**
75
75
  * Flat-edge adjacency matrix for cycle-breaking. Allocated per-rank by
76
- * flatBreakcycles when any flat edges exist; freed in cleanup2.
76
+ * flatBreakcycles when any flat edges exist. Left set after cleanup2, as
77
+ * C's free_matrix leaves the pointer: flat_edges reads it as a flag.
77
78
  * @see lib/dotgen/mincross.c:GD_rank(g)[r].flat
79
+ * @see lib/dotgen/flat.c:flat_edges (16.1.1) 274
78
80
  */
79
81
  flat?: AdjMatrix;
80
82
 
@@ -23,7 +23,6 @@ import { gvQsort } from "../util/bsd-qsort.js";
23
23
  import { agwarningf } from '../common/agerr.js';
24
24
 
25
25
  export type { OrthoGraph, OrthoEdge, OrthoNode, OrthoPoint, ClipAndInstallFn };
26
- export { SEED } from "./partition.js";
27
26
 
28
27
  // ─── Edge length / sorting ────────────────────────────────────────────────────
29
28
 
@@ -7,23 +7,19 @@
7
7
  * (via perp()). Intersection of the two decompositions yields cells
8
8
  * bounded on all four sides.
9
9
  *
10
- * SEED is fixed at 173 — matches lib/ortho/partition.c:srand48(173).
10
+ * The segment permutation draws from the process-global libc rand() stream
11
+ * (graphviz 16.1.1, b99490ece): partition no longer seeds srand48(173).
11
12
  *
12
13
  * @see lib/ortho/partition.c
13
14
  */
14
15
 
15
- import { srand48, drand48 } from "../common/random.js";
16
+ import { gvPermutation } from "../common/crand.js";
16
17
  import type { OrthoBox, OrthoPoint, Cell } from "./types.js";
17
18
  import {
18
19
  constructTrapezoids, fpEqual, greaterThan, isValidTrap, C_EPS, equalTo,
19
20
  } from "./trapezoid.js";
20
21
  import type { SegmentT, TrapT } from "./trapezoid.js";
21
22
 
22
- /** Fixed RNG seed — matches lib/ortho/partition.c:srand48(173) */
23
- const SEED = 173;
24
-
25
- export { SEED };
26
-
27
23
  const NPOINTS = 4;
28
24
 
29
25
  /** @see lib/ortho/partition.c:#define TR_FROM_UP/TR_FROM_DN */
@@ -86,20 +82,14 @@ class PartitionHelper {
86
82
  }
87
83
 
88
84
  /**
89
- * Generate a random permutation of the segments 1..n, drawing from the
90
- * process-global POSIX drand48 stream (seeded by partition's srand48).
85
+ * Generate a random permutation of the segments 1..n: gv_permutation's
86
+ * Fisher-Yates shuffle over the global libc rand() stream, made 1-based.
91
87
  * @see lib/ortho/partition.c:generateRandomOrdering
92
88
  */
93
89
  static generateRandomOrdering(n: number): number[] {
94
- const permute: number[] = [];
95
- for (let i = 0; i < n; i++) permute.push(i + 1);
96
- for (let i = 0; i < n; i++) {
97
- // C: j = (size_t)((double)i + drand48() * (double)(n - i));
98
- const j = Math.floor(i + drand48() * (n - i));
99
- if (j !== i) {
100
- const tmp = permute[i]; permute[i] = permute[j]; permute[j] = tmp;
101
- }
102
- }
90
+ const permute = gvPermutation(n);
91
+ // make indexing 1-based
92
+ for (let i = 0; i < n; i++) permute[i]!++;
103
93
  return permute;
104
94
  }
105
95
 
@@ -271,10 +261,8 @@ export function partition(cells: Cell[], bb: OrthoBox): OrthoBox[] | null {
271
261
  const h = PartitionHelper;
272
262
  const nsegs = 4 * (cells.length + 1);
273
263
 
274
- // C: srand48(173) once, then two generateRandomOrdering calls share the
275
- // continuing drand48 stream (partition.c:737-763).
276
- srand48(SEED);
277
-
264
+ // C: the two generateRandomOrdering calls share the continuing rand()
265
+ // stream (partition.c:677, :693).
278
266
  const hSeg = h.genSegments(cells, bb, false);
279
267
  const hPerm = h.generateRandomOrdering(nsegs);
280
268
  const hTr = constructTrapezoids(nsegs, hSeg, hPerm);
@@ -11,6 +11,7 @@ import { Node } from '../model/node.js';
11
11
  import { Edge } from '../model/edge.js';
12
12
  import { assignSubgSeq } from '../model/cgraph-ops.js';
13
13
  import { htmlValueContent, isHtmlValue } from '../common/html-string.js';
14
+ import { effectiveGraphDefaults, hasLocalGraphSym, pinSubgraphsAttr } from './graph-attr-syms.js';
14
15
  import type {
15
16
  AttrPair,
16
17
  NodeId,
@@ -74,28 +75,6 @@ function effectiveNodeDefaults(scope: Graph): Map<string, string> {
74
75
  return eff;
75
76
  }
76
77
 
77
- /** Graph-attr keys do_graph_label inherits; seeded into subgraph attrs so the
78
- * inherited value survives the layout's cluster rebuilds (which copy attrs but
79
- * not the snapshot). `labelloc`/`labeljust` drive cluster label position and
80
- * inherit via C `agget` just like label/font — @see input.c:858-877. */
81
- const GRAPH_LABEL_INHERIT_KEYS = ['label', 'fontname', 'fontsize', 'fontcolor', 'labelloc', 'labeljust'] as const;
82
-
83
- /**
84
- * Collect the graph-attribute defaults in effect at `scope`: walk scope -> root,
85
- * inner overriding outer (first-found wins), reading each graph's own `attrs`.
86
- * Snapshotted when a subgraph opens so an ancestor attribute set LATER in
87
- * statement order does not retroactively apply (DOT's order-sensitive defaults).
88
- */
89
- function effectiveGraphDefaults(scope: Graph): Map<string, string> {
90
- const eff = new Map<string, string>();
91
- for (let g: Graph | null = scope; g !== null; g = g.parent) {
92
- for (const [k, v] of g.attrs) {
93
- if (!eff.has(k)) eff.set(k, v);
94
- }
95
- }
96
- return eff;
97
- }
98
-
99
78
  /** Manages the per-parse node ID counter and node creation. */
100
79
  export class NodeRegistry {
101
80
  private nextId = 0;
@@ -117,35 +96,6 @@ export class NodeRegistry {
117
96
  }
118
97
  }
119
98
 
120
- // ── Endpoint / name collection ────────────────────────────────────────────────
121
-
122
- /** Collects node names from AST statement lists (for edge endpoint expansion). */
123
- export class NameCollector {
124
- static fromStmts(stmts: ParsedStmt[]): string[] {
125
- const out: string[] = [];
126
- for (const s of stmts) NameCollector.fromStmt(s, out);
127
- return out;
128
- }
129
-
130
- static fromStmt(stmt: ParsedStmt, out: string[]): void {
131
- if (stmt.type === 'node') {
132
- out.push(stmt.id.id);
133
- } else if (stmt.type === 'edge') {
134
- for (const item of stmt.nodes) NameCollector.fromEndpoint(item, out);
135
- } else if (stmt.type === 'subgraph') {
136
- out.push(...NameCollector.fromStmts(stmt.stmts));
137
- }
138
- }
139
-
140
- static fromEndpoint(item: NodeId | SubgraphStmt, out: string[]): void {
141
- if ('type' in item && item.type === 'subgraph') {
142
- out.push(...NameCollector.fromStmts(item.stmts));
143
- } else {
144
- out.push((item as NodeId).id);
145
- }
146
- }
147
- }
148
-
149
99
  // ── Statement processors ──────────────────────────────────────────────────────
150
100
 
151
101
  /** Processes individual parsed statements into graph model objects. */
@@ -226,26 +176,36 @@ export class StmtProcessor {
226
176
  }
227
177
 
228
178
  processAssign(stmt: AssignStmt, graph: Graph): void {
229
- graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
230
179
  // cgraph: assigning a graph attr on any (sub)graph declares it graph-wide
231
180
  // with an empty default → the root sees "" for it. @see agattr declaration.
232
181
  this.declareGraphAttr(graph, stmt.key);
182
+ graph.attrs.set(stmt.key, normaliseAttrValue(stmt.value));
233
183
  }
234
184
 
235
- /** Record a graph-attribute declaration, noting whether THIS scope was the
236
- * first to declare the key anywhere — the branch selector in cgraph's
237
- * setattr. @see lib/cgraph/attr.c:257 · model/graph.ts firstGraphDecl */
185
+ /** Record a graph-attribute declaration, BEFORE its value is stored, noting
186
+ * whether THIS scope was the first to declare the key anywhere — the branch
187
+ * selector in cgraph's setattr. @see model/graph.ts firstGraphDecl
188
+ * A scope that already holds a symbol for the key (the root always; the
189
+ * first declarer, through bindattrs' empty declaration) updates it, which
190
+ * first pins its direct subgraphs; a new local definition pins nothing.
191
+ * A key declared in a re-opened subgraph's later body gets a local symbol,
192
+ * so it is no longer a seeded one. @see lib/cgraph/attr.c:setattr */
238
193
  private declareGraphAttr(graph: Graph, key: string): void {
239
- if (!graph.root.declaredGraphAttrs.has(key)) {
194
+ const first = !graph.root.declaredGraphAttrs.has(key);
195
+ if (first) {
240
196
  (graph.firstGraphDecl ??= new Set()).add(key);
241
197
  graph.root.declaredGraphAttrs.add(key);
242
198
  }
199
+ if (first || hasLocalGraphSym(graph, key)) pinSubgraphsAttr(graph, key);
200
+ graph.seededAttrs?.delete(key);
243
201
  }
244
202
 
245
203
  processAttr(stmt: AttrStmt, graph: Graph): void {
246
204
  if (stmt.target === 'graph') {
247
- applyAttrs(stmt.attrs, graph.attrs);
248
- for (const a of stmt.attrs) this.declareGraphAttr(graph, a.key);
205
+ for (const a of stmt.attrs) {
206
+ this.declareGraphAttr(graph, a.key);
207
+ applyAttrs([a], graph.attrs);
208
+ }
249
209
  } else if (stmt.target === 'node') {
250
210
  applyAttrs(stmt.attrs, graph.nodeDefaults);
251
211
  } else {
@@ -269,10 +229,21 @@ export class StmtProcessor {
269
229
  // (A -> {S} -> B) appears in two adjacent pairs, so resolving once avoids
270
230
  // double-creating it. Endpoints (incl. subgraphs) open before any edge of the
271
231
  // statement is built — matching cgraph's grammar. @see lib/cgraph/grammar.y
272
- const ends = stmt.nodes.map((item) => ({
273
- nodes: this.resolveEndpoint(item, root, graph, directed),
232
+ const refs = stmt.nodes.map((item) => ({
233
+ ref: this.resolveEndpoint(item, root, graph, directed),
274
234
  port: portStringOf(item),
275
235
  }));
236
+ // A subgraph endpoint expands to the nodes the subgraph holds once the
237
+ // WHOLE statement is parsed, walked in sequence (node id) order: an earlier
238
+ // body of a re-opened subgraph and a later endpoint naming the same
239
+ // subgraph both count. Walking the node dictionary rather than the written
240
+ // order gives graphs-world `37 -> {39;41;38;40}` heads 38,40,39,41, and
241
+ // makes a name written twice in the endpoint one member (1902 drew a1->a3
242
+ // twice). @see lib/cgraph/grammar.y:endedge, edgerhs (agfstnode/agnxtnode)
243
+ const ends = refs.map(({ ref, port }) => ({
244
+ nodes: ref instanceof Graph ? [...ref.nodes.values()].sort((a, b) => a.id - b.id) : ref,
245
+ port,
246
+ }));
276
247
  for (let i = 0; i < ends.length - 1; i++) {
277
248
  this.connectEndpoints(ends[i], ends[i + 1], stmt.attrs, graph, root);
278
249
  }
@@ -294,34 +265,45 @@ export class StmtProcessor {
294
265
  // enclosing scope have already advanced it — matching native's %N exactly.
295
266
  // @see lib/cgraph/graph.c:agsubg, lib/cgraph/id.c:idmap
296
267
  const sgName = stmt.id ?? `%${this.nextAnonId()}`;
297
- // AGSEQ is assigned when the subgraph opens, before its body — matching C's
298
- // agopen, which calls agnextseq before processing the subgraph contents.
299
- // A reopened named subgraph (`subgraph X {…} … subgraph X {…}`) consumes no
300
- // new AGSEQ in cgraph, so reuse the prior seq rather than re-incrementing.
301
- // (Content still overwrites; merge semantics are unchanged and out of scope.)
268
+ // A re-opened named subgraph (`subgraph X {…} … subgraph X {…}`) is the one
269
+ // the parent already holds: agsubg finds it by name among the parent's OWN
270
+ // subgraphs and returns it. The body adds to it; it takes no new AGSEQ, and
271
+ // the attribute values it copied when it first opened stay as they were.
272
+ // @see lib/cgraph/subg.c:agsubg, lib/cgraph/grammar.y:opensubg
302
273
  const prior = graph.subgraphs.get(sgName);
274
+ if (prior !== undefined) {
275
+ buildGraph(stmt.stmts, prior, root, directed, this);
276
+ return prior;
277
+ }
303
278
  const sg = new Graph(sgName, graph.kind);
304
279
  sg.parent = graph;
305
280
  sg.root = root;
306
- if (prior !== undefined) sg.seq = prior.seq;
307
- else assignSubgSeq(graph, sg);
281
+ // AGSEQ is assigned when the subgraph opens, before its body — matching C's
282
+ // agopen, which calls agnextseq before processing the subgraph contents.
283
+ assignSubgSeq(graph, sg);
308
284
  // Snapshot the enclosing graph-attribute defaults at OPEN time (before the
309
285
  // body) so a later ancestor `graph [label=…]` does not apply to this
310
286
  // subgraph — matching cgraph's parse-time defval copy (order-sensitive).
311
287
  sg.graphDefaultsSnapshot = effectiveGraphDefaults(graph);
312
288
  buildGraph(stmt.stmts, sg, root, directed, this);
313
- // Seed the order-correct inherited label-family defaults into the subgraph's
314
- // OWN attrs (body wins) so they survive the layout's cluster rebuilds, which
315
- // copy attrs but not the snapshot. Mirrors cgraph's agsubg defval copy; kept
316
- // to the keys do_graph_label reads so the blast radius stays in label render.
317
- // @see lib/common/input.c:do_graph_label (agget label/font*)
318
- // The seeded keys are recorded so the -Tdot serializer can tell them from a
319
- // genuine local declaration: cgraph gives a local declaration its own dict
320
- // symbol (printed by write_dict) even when the value equals the inherited
321
- // one, whereas a seeded value must stay invisible. @see src/render/dot.ts
322
- for (const key of GRAPH_LABEL_INHERIT_KEYS) {
323
- const v = sg.graphDefaultsSnapshot.get(key);
324
- if (v !== undefined && !sg.attrs.has(key)) {
289
+ // Seed every inherited value into the subgraph's OWN attrs (body wins):
290
+ // agmakeattrs copies each graph attribute in effect in the parent into a
291
+ // new subgraph's record, and every agget(subg, …) reads that copy — the
292
+ // label family (do_graph_label; labelloc/labeljust too, input.c:858-877),
293
+ // `cluster` (is_a_cluster), `ordering`, `rank`, and the rest. Seeding,
294
+ // unlike a read of the snapshot, survives every copy that takes `attrs`
295
+ // alone: the layout's cluster rebuilds and dot's pack projection (C's
296
+ // agcopyattr copies the effective values there).
297
+ // @see lib/cgraph/attr.c:agmakeattrs
298
+ // @see lib/common/input.c:do_graph_label
299
+ // @see lib/common/utils.c:is_a_cluster
300
+ // The seeded keys are recorded so the writers can tell them from a local
301
+ // declaration: cgraph gives a local declaration its own dict symbol
302
+ // (printed by write_dict) even when the value equals the inherited one,
303
+ // whereas a seeded value has none and must stay invisible.
304
+ // @see src/render/dot/attrs.ts, src/model/cgraph-ops.ts:localGraphAttrs
305
+ for (const [key, v] of sg.graphDefaultsSnapshot) {
306
+ if (!sg.attrs.has(key)) {
325
307
  sg.attrs.set(key, v);
326
308
  (sg.seededAttrs ??= new Set()).add(key);
327
309
  }
@@ -360,35 +342,20 @@ export class StmtProcessor {
360
342
  }
361
343
  }
362
344
 
345
+ /** One endpoint of an edge statement: a node item's node, or a subgraph
346
+ * item's subgraph, which the caller expands after the whole statement. */
363
347
  private resolveEndpoint(
364
348
  item: NodeId | SubgraphStmt,
365
349
  root: Graph,
366
350
  scope: Graph,
367
351
  directed: boolean,
368
- ): Node[] {
352
+ ): Node[] | Graph {
369
353
  if ('type' in item && item.type === 'subgraph') {
370
354
  // Create the subgraph as a first-class object so its rank-set attr
371
355
  // (rank=same/min/max/source/sink), node membership, and anon-id/AGSEQ are
372
- // registered for collapse_sets; then expand the edge over its node names.
373
- this.processSubgraph(item, scope, root, directed);
374
- // Ensure (create/look-up) the member nodes in written order, so NEW nodes
375
- // take their AGSEQ in source order — then iterate them in AGSEQ (node id)
376
- // order for edge creation. C builds `tail -> {set}` edges by walking the
377
- // endpoint subgraph's node dictionary (sequence-ordered), not the written
378
- // order; iterating out of order assigns the wrong graphSeq (SVG edge id)
379
- // when the set lists pre-existing nodes out of creation order (graphs-world
380
- // `37 -> {39;41;38;40}`: heads 38,40,39,41 by AGSEQ, not 39,41,38,40).
381
- // @see lib/cgraph/edge.c:agedge — edges follow agfstnode/agnxtnode order
382
- // Dedup by node identity: a name appearing in several statements of the
383
- // endpoint subgraph (e.g. a1 in both `a1->a2` and `b2->a1`) is ONE member
384
- // in cgraph's node dictionary, so `subg -> x` expands to a single a1->x —
385
- // not one per textual occurrence (1902 drew a1->a3 twice).
386
- // @see lib/cgraph/edge.c:agedge (walks agfstnode/agnxtnode — unique nodes)
387
- const seen = new Set<number>();
388
- const nodes = NameCollector.fromStmts(item.stmts)
389
- .map((n) => this.registry.ensure(n, root, scope))
390
- .filter((nd) => (seen.has(nd.id) ? false : (seen.add(nd.id), true)));
391
- return nodes.sort((a, b) => a.id - b.id);
356
+ // registered for collapse_sets. Its body creates the member nodes in
357
+ // written order, so NEW nodes take their AGSEQ in source order.
358
+ return this.processSubgraph(item, scope, root, directed);
392
359
  }
393
360
  return [this.registry.ensure((item as NodeId).id, root, scope)];
394
361
  }
@@ -0,0 +1,62 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+ /**
3
+ * The builder's model of cgraph's graph-attribute symbols: which graphs hold
4
+ * a local dict symbol for a key, and what a subgraph copies when it opens.
5
+ * @see lib/cgraph/attr.c
6
+ */
7
+ import type { Graph } from '../model/graph.js';
8
+
9
+ /**
10
+ * Whether `g` holds a local dict symbol for graph attribute `key`. The root
11
+ * holds every declared key (a global definition goes into its dict); a
12
+ * subgraph holds the keys it declared and the ones it was pinned with. A
13
+ * seeded value is inherited through the dict view and has no symbol.
14
+ * @see lib/cgraph/attr.c:aglocaldictsym
15
+ */
16
+ export function hasLocalGraphSym(g: Graph, key: string): boolean {
17
+ if (g.parent === null) return g.declaredGraphAttrs.has(key);
18
+ if (g.pinnedAttrs?.has(key) === true) return true;
19
+ return g.attrs.has(key) && g.seededAttrs?.has(key) !== true;
20
+ }
21
+
22
+ /**
23
+ * Give each direct subgraph of `parent` with no local symbol for `key` one
24
+ * holding its current value: `parent` is about to update its own symbol.
25
+ * The value stays in the subgraph's `attrs` (absent for the empty default).
26
+ * @see lib/cgraph/attr.c:unviewsubgraphsattr
27
+ */
28
+ export function pinSubgraphsAttr(parent: Graph, key: string): void {
29
+ for (const sub of parent.subgraphs.values()) {
30
+ if (!hasLocalGraphSym(sub, key)) (sub.pinnedAttrs ??= new Set()).add(key);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * The graph-attribute values a subgraph opening in `scope` copies: for each
36
+ * key, the `defval` of the nearest local symbol on the dict view scope ->
37
+ * root, which is what `agmakeattrs` iterates. A graph's value for a key it
38
+ * holds a symbol for is its `attrs` entry (absent: the empty default, which
39
+ * the copy leaves out). Until a subgraph is re-opened these are the current
40
+ * values of the enclosing graphs; a re-opened one may hold a seeded value
41
+ * that a nearer symbol above it overrides, or a pin that hides a later one.
42
+ * Snapshotted when a subgraph opens so an ancestor attribute set LATER in
43
+ * statement order does not retroactively apply (DOT's order-sensitive defaults).
44
+ * @see lib/cgraph/attr.c:agmakeattrs
45
+ */
46
+ export function effectiveGraphDefaults(scope: Graph): Map<string, string> {
47
+ const eff = new Map<string, string>();
48
+ const found = new Set<string>();
49
+ const take = (g: Graph, key: string): void => {
50
+ if (found.has(key)) return;
51
+ found.add(key);
52
+ const v = g.attrs.get(key);
53
+ if (v !== undefined) eff.set(key, v);
54
+ };
55
+ for (let g: Graph | null = scope; g !== null; g = g.parent) {
56
+ for (const key of g.attrs.keys()) {
57
+ if (g.seededAttrs?.has(key) !== true) take(g, key);
58
+ }
59
+ for (const key of g.pinnedAttrs ?? []) take(g, key);
60
+ }
61
+ return eff;
62
+ }
@@ -15,7 +15,8 @@ interface LineCoeff { xc0: number; xc1: number; yc0: number; yc1: number; }
15
15
  interface RootAccum { roots: number[]; n: number; }
16
16
  interface RouteState { ops: Point[]; barriers: Edge[]; }
17
17
 
18
- class RouteHelper {
18
+ /** @internal — exported for route.branch.test.ts */
19
+ export class RouteHelper {
19
20
  static B0(t: number): number { const u = 1-t; return u*u*u; }
20
21
  static B1(t: number): number { const u = 1-t; return 3*t*u*u; }
21
22
  static B2(t: number): number { const u = 1-t; return 3*t*t*u; }
@@ -71,6 +72,15 @@ class RouteHelper {
71
72
  c[0] = v0;
72
73
  }
73
74
 
75
+ /**
76
+ * `a == b` within a tolerance (16.1.1 `d3ab9ba47`; the same 1e-7 as solve3).
77
+ * @see lib/pathplan/route.c:eq
78
+ */
79
+ static eq(a: number, b: number): boolean {
80
+ const EPS = 1e-7;
81
+ return Math.abs(a - b) < EPS;
82
+ }
83
+
74
84
  static addRoot(root: number, acc: RootAccum): void {
75
85
  if (root >= 0 && root <= 1) { acc.roots[acc.n] = root; acc.n++; }
76
86
  }
@@ -91,7 +101,7 @@ class RouteHelper {
91
101
  } else {
92
102
  for (let i = 0; i < xn; i++)
93
103
  for (let j = 0; j < yn; j++)
94
- if (xr[i] === yr[j]) RouteHelper.addRoot(xr[i], acc);
104
+ if (RouteHelper.eq(xr[i], yr[j])) RouteHelper.addRoot(xr[i], acc);
95
105
  }
96
106
  return acc.n;
97
107
  }
@@ -144,8 +154,8 @@ class RouteHelper {
144
154
  yc0: lps[0].y, yc1: lps[1].y - lps[0].y,
145
155
  };
146
156
  const acc: RootAccum = { roots, n: 0 };
147
- if (lc.xc1 === 0) {
148
- if (lc.yc1 === 0) return RouteHelper.silBothZero(sps, lc, acc);
157
+ if (RouteHelper.eq(lc.xc1, 0)) {
158
+ if (RouteHelper.eq(lc.yc1, 0)) return RouteHelper.silBothZero(sps, lc, acc);
149
159
  return RouteHelper.silXzeroYnonzero(sps, lc, acc);
150
160
  }
151
161
  return RouteHelper.silGeneral(sps, lc, acc);