@knowvah/dot-engine 2.12.1 → 2.12.3

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 (308) 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/compass-port.d.ts.map +1 -1
  6. package/dist/common/edge-label-init.d.ts +26 -1
  7. package/dist/common/edge-label-init.d.ts.map +1 -1
  8. package/dist/common/graph-init.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/nodeinit.d.ts +16 -2
  19. package/dist/common/nodeinit.d.ts.map +1 -1
  20. package/dist/common/poly-inside.d.ts.map +1 -1
  21. package/dist/common/splines-geom.d.ts +2 -1
  22. package/dist/common/splines-geom.d.ts.map +1 -1
  23. package/dist/common/splines-path-begin.d.ts.map +1 -1
  24. package/dist/common/splines-path-end.d.ts.map +1 -1
  25. package/dist/common/splines-routespl.d.ts +3 -0
  26. package/dist/common/splines-routespl.d.ts.map +1 -1
  27. package/dist/gvc/context.d.ts +8 -0
  28. package/dist/gvc/context.d.ts.map +1 -1
  29. package/dist/gvc/emit-gates.d.ts +5 -10
  30. package/dist/gvc/emit-gates.d.ts.map +1 -1
  31. package/dist/gvc/emit-xdot.d.ts +7 -6
  32. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  33. package/dist/gvc/job.d.ts +5 -2
  34. package/dist/gvc/job.d.ts.map +1 -1
  35. package/dist/gvc/viewport.d.ts +10 -5
  36. package/dist/gvc/viewport.d.ts.map +1 -1
  37. package/dist/index.js +21565 -21326
  38. package/dist/index.js.map +4 -4
  39. package/dist/layout/dot/classify.d.ts.map +1 -1
  40. package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
  41. package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
  42. package/dist/layout/dot/edge-route-chain.d.ts +20 -16
  43. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  44. package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
  45. package/dist/layout/dot/edge-route.d.ts +7 -3
  46. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  47. package/dist/layout/dot/fastgr.d.ts +5 -3
  48. package/dist/layout/dot/fastgr.d.ts.map +1 -1
  49. package/dist/layout/dot/flat-adj-record.d.ts +22 -0
  50. package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
  51. package/dist/layout/dot/flat.d.ts +22 -7
  52. package/dist/layout/dot/flat.d.ts.map +1 -1
  53. package/dist/layout/dot/init.d.ts +49 -9
  54. package/dist/layout/dot/init.d.ts.map +1 -1
  55. package/dist/layout/dot/mincross-build.d.ts +6 -0
  56. package/dist/layout/dot/mincross-build.d.ts.map +1 -1
  57. package/dist/layout/dot/mincross-flat.d.ts +10 -1
  58. package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
  59. package/dist/layout/dot/mincross.d.ts +6 -1
  60. package/dist/layout/dot/mincross.d.ts.map +1 -1
  61. package/dist/layout/dot/ns-subtree.d.ts +9 -6
  62. package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
  63. package/dist/layout/dot/pack-components.d.ts +4 -3
  64. package/dist/layout/dot/pack-components.d.ts.map +1 -1
  65. package/dist/layout/dot/position-aux.d.ts +69 -21
  66. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  67. package/dist/layout/dot/position-bbox.d.ts.map +1 -1
  68. package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
  69. package/dist/layout/dot/position.d.ts.map +1 -1
  70. package/dist/layout/dot/rank-dot2.d.ts +7 -25
  71. package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
  72. package/dist/layout/dot/self-loop.d.ts +11 -4
  73. package/dist/layout/dot/self-loop.d.ts.map +1 -1
  74. package/dist/layout/dot/splines-clone.d.ts +2 -1
  75. package/dist/layout/dot/splines-clone.d.ts.map +1 -1
  76. package/dist/layout/dot/splines-flat-labeled.d.ts.map +1 -1
  77. package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
  78. package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
  79. package/dist/layout/dot/splines-flat.d.ts +18 -0
  80. package/dist/layout/dot/splines-flat.d.ts.map +1 -1
  81. package/dist/layout/dot/splines-groups.d.ts.map +1 -1
  82. package/dist/layout/dot/splines-route.d.ts +6 -3
  83. package/dist/layout/dot/splines-route.d.ts.map +1 -1
  84. package/dist/layout/dot/straight-edges.d.ts.map +1 -1
  85. package/dist/layout/fdp/ports.d.ts.map +1 -1
  86. package/dist/layout/fdp/tlayout.d.ts +3 -0
  87. package/dist/layout/fdp/tlayout.d.ts.map +1 -1
  88. package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
  89. package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
  90. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
  91. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
  92. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  93. package/dist/layout/neato/conjgrad.d.ts +7 -6
  94. package/dist/layout/neato/conjgrad.d.ts.map +1 -1
  95. package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
  96. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
  97. package/dist/layout/neato/matrix-ops.d.ts +0 -6
  98. package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
  99. package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
  100. package/dist/layout/neato/sgd.d.ts.map +1 -1
  101. package/dist/model/cgraph-ops.d.ts +10 -2
  102. package/dist/model/cgraph-ops.d.ts.map +1 -1
  103. package/dist/model/edge.d.ts +7 -2
  104. package/dist/model/edge.d.ts.map +1 -1
  105. package/dist/model/edgeInfo.d.ts +17 -2
  106. package/dist/model/edgeInfo.d.ts.map +1 -1
  107. package/dist/model/graph.d.ts +4 -3
  108. package/dist/model/graph.d.ts.map +1 -1
  109. package/dist/model/lazy-attrs.d.ts.map +1 -1
  110. package/dist/model/rankEntry.d.ts +3 -1
  111. package/dist/model/rankEntry.d.ts.map +1 -1
  112. package/dist/ortho/index.d.ts +0 -1
  113. package/dist/ortho/index.d.ts.map +1 -1
  114. package/dist/ortho/partition.d.ts +2 -4
  115. package/dist/ortho/partition.d.ts.map +1 -1
  116. package/dist/parser/builder.d.ts.map +1 -1
  117. package/dist/pathplan/route.d.ts +93 -0
  118. package/dist/pathplan/route.d.ts.map +1 -1
  119. package/dist/render/dot/agwrite.d.ts +26 -10
  120. package/dist/render/dot/agwrite.d.ts.map +1 -1
  121. package/dist/render/dot/attrs.d.ts +15 -4
  122. package/dist/render/dot/attrs.d.ts.map +1 -1
  123. package/dist/render/dot/types.d.ts +7 -2
  124. package/dist/render/dot/types.d.ts.map +1 -1
  125. package/dist/render/dot/write-back.d.ts +14 -0
  126. package/dist/render/dot/write-back.d.ts.map +1 -1
  127. package/dist/render/dot/xdot-ops.d.ts +20 -29
  128. package/dist/render/dot/xdot-ops.d.ts.map +1 -1
  129. package/dist/render/dot.d.ts +4 -2
  130. package/dist/render/dot.d.ts.map +1 -1
  131. package/dist/render/json-cluster-edge.d.ts +17 -4
  132. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  133. package/dist/render/json-nonfinite.d.ts +17 -0
  134. package/dist/render/json-nonfinite.d.ts.map +1 -0
  135. package/dist/render/json.d.ts +4 -0
  136. package/dist/render/json.d.ts.map +1 -1
  137. package/dist/render/map.d.ts +3 -0
  138. package/dist/render/map.d.ts.map +1 -1
  139. package/dist/render/svg-graph.d.ts.map +1 -1
  140. package/dist/render/svg-id.d.ts +10 -1
  141. package/dist/render/svg-id.d.ts.map +1 -1
  142. package/dist/render/svg.d.ts +3 -1
  143. package/dist/render/svg.d.ts.map +1 -1
  144. package/dist/render.js +21517 -21278
  145. package/dist/render.js.map +4 -4
  146. package/dist/util/bsd-qsort.d.ts.map +1 -1
  147. package/dist/util/overflow.d.ts +37 -0
  148. package/dist/util/overflow.d.ts.map +1 -0
  149. package/dist/xdot/parse.d.ts.map +1 -1
  150. package/dist/xdot/strtod.d.ts +23 -0
  151. package/dist/xdot/strtod.d.ts.map +1 -0
  152. package/package.json +3 -2
  153. package/src/api/builder.ts +8 -2
  154. package/src/common/compass-port.ts +36 -20
  155. package/src/common/edge-label-init.ts +43 -17
  156. package/src/common/graph-init.ts +11 -1
  157. package/src/common/htmltable-label.ts +9 -4
  158. package/src/common/htmltable-lex.ts +5 -2
  159. package/src/common/htmltable-parse-image.ts +69 -0
  160. package/src/common/htmltable-parse-state.ts +6 -0
  161. package/src/common/htmltable-parse.ts +34 -44
  162. package/src/common/nodeinit.ts +28 -8
  163. package/src/common/poly-inside.ts +11 -5
  164. package/src/common/splines-geom.ts +24 -6
  165. package/src/common/splines-path-begin.ts +4 -3
  166. package/src/common/splines-path-end.ts +4 -3
  167. package/src/common/splines-routespl.ts +32 -0
  168. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
  169. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
  170. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
  171. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
  172. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
  173. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
  174. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
  175. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
  176. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
  177. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
  178. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
  179. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
  180. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
  181. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
  182. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
  183. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
  184. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
  185. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
  186. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
  187. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
  188. package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
  189. package/src/gvc/context.ts +8 -0
  190. package/src/gvc/device.ts +6 -6
  191. package/src/gvc/emit-gates.ts +6 -15
  192. package/src/gvc/emit-xdot.ts +10 -11
  193. package/src/gvc/job.ts +5 -2
  194. package/src/gvc/viewport.ts +13 -7
  195. package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
  196. package/src/layout/dot/classify.ts +5 -2
  197. package/src/layout/dot/edge-route-chain-views.ts +120 -0
  198. package/src/layout/dot/edge-route-chain.ts +103 -117
  199. package/src/layout/dot/edge-route-faithful.ts +20 -5
  200. package/src/layout/dot/edge-route.ts +44 -49
  201. package/src/layout/dot/fastgr.ts +9 -3
  202. package/src/layout/dot/flat-adj-record.ts +68 -0
  203. package/src/layout/dot/flat.ts +38 -17
  204. package/src/layout/dot/init.ts +59 -13
  205. package/src/layout/dot/mincross-build.ts +14 -1
  206. package/src/layout/dot/mincross-flat.ts +15 -5
  207. package/src/layout/dot/mincross.ts +6 -2
  208. package/src/layout/dot/ns-subtree.ts +11 -7
  209. package/src/layout/dot/pack-components.ts +6 -4
  210. package/src/layout/dot/position-aux.ts +122 -42
  211. package/src/layout/dot/position-bbox.ts +14 -1
  212. package/src/layout/dot/position-ycoords.ts +7 -1
  213. package/src/layout/dot/position.ts +4 -1
  214. package/src/layout/dot/rank-dot2.ts +13 -94
  215. package/src/layout/dot/self-loop.ts +29 -11
  216. package/src/layout/dot/splines-clone.ts +8 -2
  217. package/src/layout/dot/splines-flat-labeled.ts +3 -2
  218. package/src/layout/dot/splines-flat-multi.ts +12 -4
  219. package/src/layout/dot/splines-flat.ts +9 -19
  220. package/src/layout/dot/splines-groups.ts +5 -3
  221. package/src/layout/dot/splines-route.ts +10 -11
  222. package/src/layout/dot/straight-edges.ts +5 -3
  223. package/src/layout/fdp/ports.ts +6 -2
  224. package/src/layout/fdp/tlayout.ts +6 -5
  225. package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
  226. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
  227. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
  228. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
  229. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
  230. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
  231. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
  232. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
  233. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
  234. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
  235. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
  236. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
  237. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
  238. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
  239. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
  240. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
  241. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
  242. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
  243. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
  244. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
  245. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
  246. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
  247. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
  248. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
  249. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
  250. package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
  251. package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
  252. package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
  253. package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
  254. package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
  255. package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
  256. package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
  257. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
  258. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
  259. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
  260. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
  261. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
  262. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
  263. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
  264. package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
  265. package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
  266. package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
  267. package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
  268. package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
  269. package/src/layout/neato/conjgrad-mkernel.ts +6 -2
  270. package/src/layout/neato/conjgrad.ts +38 -35
  271. package/src/layout/neato/matrix-ops-dense.ts +2 -20
  272. package/src/layout/neato/matrix-ops.ts +0 -20
  273. package/src/layout/neato/quad-prog-vpsc.ts +7 -5
  274. package/src/layout/neato/sgd.ts +2 -1
  275. package/src/layout/neato/smart-ini-x.ts +15 -15
  276. package/src/layout/neato/stress-subspace.ts +5 -5
  277. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
  278. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
  279. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
  280. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
  281. package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
  282. package/src/model/cgraph-ops.ts +4 -3
  283. package/src/model/edge.ts +11 -4
  284. package/src/model/edgeInfo.ts +18 -2
  285. package/src/model/graph.ts +4 -3
  286. package/src/model/lazy-attrs.ts +3 -1
  287. package/src/model/rankEntry.ts +3 -1
  288. package/src/ortho/index.ts +0 -1
  289. package/src/ortho/partition.ts +10 -22
  290. package/src/parser/builder.ts +12 -3
  291. package/src/pathplan/route.ts +14 -4
  292. package/src/render/dot/agwrite.ts +45 -18
  293. package/src/render/dot/attrs.ts +18 -7
  294. package/src/render/dot/types.ts +7 -2
  295. package/src/render/dot/write-back.ts +27 -3
  296. package/src/render/dot/xdot-ops.ts +25 -56
  297. package/src/render/dot.ts +7 -5
  298. package/src/render/json-cluster-edge.ts +42 -5
  299. package/src/render/json-nonfinite.ts +51 -0
  300. package/src/render/json.ts +23 -26
  301. package/src/render/map.ts +3 -0
  302. package/src/render/svg-graph.ts +3 -15
  303. package/src/render/svg-id.ts +11 -2
  304. package/src/render/svg.ts +4 -1
  305. package/src/util/bsd-qsort.ts +2 -1
  306. package/src/util/overflow.ts +74 -0
  307. package/src/xdot/parse.ts +9 -19
  308. package/src/xdot/strtod.ts +167 -0
@@ -112,8 +112,11 @@ function interclust1(g: Graph, t: Node, h: Node, e: Edge): void {
112
112
  const t0 = ufFind(t);
113
113
  const h0 = ufFind(h);
114
114
  const w = e.info.weight ?? 1;
115
- const rt = makeAuxEdge(v, t0, tLen, CL_BACK * w);
116
- const rh = makeAuxEdge(v, h0, hLen, w);
115
+ // C writes ED_to_orig on both results without a NULL test. make_aux_edge
116
+ // refuses only a length above INT_MAX (16.1.1), and these lengths are C
117
+ // `int`s (`offset = ED_minlen(e) + t_rank - h_rank`), so neither is null.
118
+ const rt = makeAuxEdge(v, t0, tLen, CL_BACK * w)!;
119
+ const rh = makeAuxEdge(v, h0, hLen, w)!;
117
120
  rt.info.to_orig = e;
118
121
  rh.info.to_orig = e;
119
122
  }
@@ -0,0 +1,120 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * Edge views make_regular_edge routes instead of the edge itself: the forward
5
+ * view of a back edge (`makefwdedge`) and the two hackflag views of an edge
6
+ * routed on another edge's virtual chain (`fwdedgea`, `fwdedgeb`). Split from
7
+ * edge-route-chain.ts, which walks the chain these views drive.
8
+ *
9
+ * @see lib/dotgen/dotsplines.c:makefwdedge
10
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (hackflag)
11
+ */
12
+
13
+ import type { Edge as GraphEdge } from '../../model/edge.js';
14
+ import type { Port } from '../../model/geom.js';
15
+ import type { Node } from '../../model/node.js';
16
+ import { VIRTUAL } from './fastgr.js';
17
+ import { makePort } from '../../model/edgeInfo.js';
18
+ import { resolveOrigEdge } from './splines.js';
19
+
20
+ // ---------------------------------------------------------------------------
21
+ // Forward view
22
+ // @see lib/dotgen/dotsplines.c:makefwdedge
23
+ // ---------------------------------------------------------------------------
24
+
25
+ /**
26
+ * Forward view of any edge (C `makefwdedge`): tail/head swapped when the edge
27
+ * runs high→low rank (a back edge), fresh portless ends. `beginPath`/`endPath`
28
+ * read `e.tail`/`e.head`, so the chain must be driven by an edge that runs
29
+ * low→high rank. Sets `to_orig`/`edge_type=VIRTUAL` so `clipAndInstall`→
30
+ * `newSpline` installs the spline on the ORIGINAL edge (its `to_orig` loop) and
31
+ * the post-routing `swapSpline` pass reverses it back to tail→head. Shares
32
+ * `attrs`/`root`/`to_virt` with `e`. Consumed by T3 for parallel back-members.
33
+ * @see lib/dotgen/dotsplines.c:makefwdedge
34
+ * @see lib/common/splines.c:clip_and_install (to_orig install loop)
35
+ */
36
+ export function makeFwdEdge(e: GraphEdge): GraphEdge {
37
+ const back = (e.head.info.rank ?? 0) < (e.tail.info.rank ?? 0);
38
+ const [tail, head] = back ? [e.head, e.tail] : [e.tail, e.head];
39
+ return {
40
+ ...e,
41
+ tail,
42
+ head,
43
+ info: {
44
+ ...e.info,
45
+ // C makefwdedge SWAPS the ports (does not strip them): a back edge keeps
46
+ // its corner ports across the forward view so make_regular_edge curls it
47
+ // (e.g. #241_0 aux back-edge clone sw/se → size 7). Stripping to an empty
48
+ // Center port straightened every port-bearing back edge (size 4).
49
+ // @see lib/dotgen/dotsplines.c:makefwdedge (ED_tail_port(new)=ED_head_port(old))
50
+ tail_port: e.info.head_port ?? makePort(),
51
+ head_port: e.info.tail_port ?? makePort(),
52
+ to_orig: e,
53
+ edge_type: VIRTUAL,
54
+ },
55
+ } as GraphEdge;
56
+ }
57
+
58
+ // ---------------------------------------------------------------------------
59
+ // Hackflag views for an edge routed on another edge's chain
60
+ // @see lib/dotgen/dotsplines.c:make_regular_edge (abs(rank diff) > 1)
61
+ // ---------------------------------------------------------------------------
62
+
63
+ /** A port copied by value, as C's struct assignment copies `port`. */
64
+ function copyPort(p: Port): Port {
65
+ return { ...p, p: { ...p.p } };
66
+ }
67
+
68
+ /**
69
+ * C's `fwdedgea`: a copy of `e` from its rank-low end to the first vnode of the
70
+ * chain, head port undefined at (0,0), VIRTUAL with `to_orig = e`. beginpath's
71
+ * side-port clip reset therefore lands on `e` itself.
72
+ */
73
+ function hackflagBeginView(e: GraphEdge, back: boolean, firstVnode: Node): GraphEdge {
74
+ const tailPort = back ? e.info.head_port : e.info.tail_port;
75
+ return {
76
+ ...e,
77
+ tail: back ? e.head : e.tail,
78
+ head: firstVnode,
79
+ info: {
80
+ ...e.info,
81
+ tail_port: copyPort(tailPort),
82
+ head_port: { ...copyPort(e.info.head_port), defined: false, p: { x: 0, y: 0 } },
83
+ edge_type: VIRTUAL,
84
+ to_orig: e,
85
+ },
86
+ } as GraphEdge;
87
+ }
88
+
89
+ /**
90
+ * C's `fwdedgeb`: for a back edge, `makefwdedge(e)` (VIRTUAL, `to_orig = e`);
91
+ * otherwise a plain struct copy of `e` that stays NORMAL, so endpath's
92
+ * side-port clip reset lands on the copy and `e` keeps its head clip.
93
+ */
94
+ function hackflagEndView(e: GraphEdge, back: boolean): GraphEdge {
95
+ if (back) return makeFwdEdge(e);
96
+ return {
97
+ ...e,
98
+ info: { ...e.info, tail_port: copyPort(e.info.tail_port), head_port: copyPort(e.info.head_port) },
99
+ } as GraphEdge;
100
+ }
101
+
102
+ /**
103
+ * The edges that drive the chain's first beginpath and last endpath. A chain
104
+ * owned by `e` itself is C's ordinary walk from the first to the last fast
105
+ * edge. A chain owned by another edge means class2 merged `e` into it
106
+ * (`merge_chain`), so `e` sits in ND_other and C's group loop hands the real
107
+ * edge to make_regular_edge, which takes the hackflag branch: beginpath on
108
+ * `fwdedgea`, endpath on `fwdedgeb`. Driving those calls with the owner's
109
+ * segments reset the owner's clip flags instead of `e`'s (plantuml-ts 41).
110
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (hackflag)
111
+ * @see lib/dotgen/class2.c:class2 (merge_chain, other_edge)
112
+ */
113
+ export function chainEnds(e: GraphEdge, segs: GraphEdge[]): [GraphEdge, GraphEdge] {
114
+ const first = segs[0];
115
+ const last = segs[segs.length - 1];
116
+ const orig = resolveOrigEdge(e);
117
+ if (resolveOrigEdge(first) === orig) return [first, last];
118
+ const back = (orig.head.info.rank ?? 0) < (orig.tail.info.rank ?? 0);
119
+ return [hackflagBeginView(orig, back, first.head), hackflagEndView(orig, back)];
120
+ }
@@ -13,7 +13,7 @@
13
13
 
14
14
  import type { Graph } from '../../model/graph.js';
15
15
  import type { Edge as GraphEdge } from '../../model/edge.js';
16
- import type { Point, Box, Port } from '../../model/geom.js';
16
+ import type { Point, Box } from '../../model/geom.js';
17
17
  import type { Node } from '../../model/node.js';
18
18
  import { VIRTUAL, NORMAL } from './fastgr.js';
19
19
  import type { NodeBox } from './edge-route-geom.js';
@@ -24,10 +24,13 @@ import { beginPath } from '../../common/splines-path-begin.js';
24
24
  import { endPath } from '../../common/splines-path-end.js';
25
25
  import { routeRegularByType } from './splines-route-type.js';
26
26
  import { edgeType, EDGETYPE_LINE, resolveOrigEdge, swapEndsP, swapEdgeSpline } from './splines.js';
27
+ import { chainEnds, makeFwdEdge } from './edge-route-chain-views.js';
27
28
  import { clipAndInstall } from '../../common/splines-clip.js';
28
29
  import { buildDotSinfo } from './self-loop.js';
29
30
  import { TOP, BOTTOM, REGULAREDGE } from '../../common/splines-constants.js';
30
- import { splineMerge, makeLineEdge, resizeVn, straightLen, straightPath } from './splines-route.js';
31
+ import {
32
+ splineMerge, makeLineEdge, resizeVn, straightLen, straightPath, nodeOutSize,
33
+ } from './splines-route.js';
31
34
  import { EDGE_LABEL } from './rank.js';
32
35
  import type { RankEntry } from '../../model/rankEntry.js';
33
36
  import { rankHt } from './edge-route-rank.js';
@@ -37,6 +40,9 @@ import {
37
40
  type BboxCtx,
38
41
  } from './edge-route-faithful.js';
39
42
 
43
+ // Re-export so callers that imported the forward view from this module keep working.
44
+ export { makeFwdEdge } from './edge-route-chain-views.js';
45
+
40
46
  // ---------------------------------------------------------------------------
41
47
  // Faithful multi-rank side-port routing (make_regular_edge hackflag path)
42
48
  // @see lib/dotgen/dotsplines.c:make_regular_edge (forward, abs(rankdiff) > 1)
@@ -85,6 +91,27 @@ function isChainVirtual(n: Node): boolean {
85
91
  return (n.info.node_type ?? NORMAL) === VIRTUAL && !splineMerge(n);
86
92
  }
87
93
 
94
+ /**
95
+ * True when n is a chain vnode with no out edge: where graphviz 16.1.1's
96
+ * make_regular_edge closes the path and drops the edge. `concentrate` leaves
97
+ * such a node at the end of an edge's `ED_to_virt` chain when it orphans the
98
+ * chain's first vnode (upstream issue 2765).
99
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (16.1.1, 4f9ef1d9e)
100
+ */
101
+ function isChainDeadEnd(n: Node): boolean {
102
+ return isChainVirtual(n) && nodeOutSize(n) === 0;
103
+ }
104
+
105
+ /**
106
+ * True when the collected chain is one C routes: it reaches `end`, the real
107
+ * node at its far side, or it stops at a dead end. A chain that stops anywhere
108
+ * else is declined.
109
+ */
110
+ function chainEndsAt(segs: GraphEdge[], end: Node): boolean {
111
+ const tip = segs[segs.length - 1].head;
112
+ return tip === end || isChainDeadEnd(tip);
113
+ }
114
+
88
115
  /**
89
116
  * straight_len smode threshold: a collinear run is segmented once it is ≥ 5
90
117
  * (4+1) with edge labels on the root graph, else ≥ 3 (2+1).
@@ -186,6 +213,27 @@ function closeSmodeSeg(w: ChainWalk, segs: GraphEdge[], ci: number, sl: number,
186
213
  return next;
187
214
  }
188
215
 
216
+ /**
217
+ * Close the path at `segs[ei].head`, a chain vnode with no out edge, and drop
218
+ * the edge. 16.1.1 fails the loop body's `ND_out(hn).size > 0` test there and
219
+ * falls into the segment close with `ND_out(hn).list[0]` NULL: maximal_bbox
220
+ * (cl_bound takes the node's own cluster), endpath on the current edge with
221
+ * the end slope constrained, then the route. `straight_path(NULL, sl)` gives
222
+ * no next edge, so after recover_slack make_regular_edge returns before any
223
+ * clip_and_install. `sl` is always 0 here: straight_len of a node with no out
224
+ * edge is 0, so smode is never entered at a dead end. C's current edge is the
225
+ * one beginpath took until the walk has advanced. Always null: the route is
226
+ * discarded, and a failed route returns before recover_slack (C's `pn == 0`).
227
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (16.1.1, 4f9ef1d9e, a79e42588)
228
+ */
229
+ function closeDeadEnd(
230
+ w: ChainWalk, beginEdge: GraphEdge, segs: GraphEdge[], ei: number, segFirst: number,
231
+ ): null {
232
+ if (!endSeg(w, ei === 0 ? beginEdge : segs[ei], segs[ei], undefined, true)) return null;
233
+ recoverSlack(segs.slice(segFirst), w.P);
234
+ return null;
235
+ }
236
+
189
237
  /** Route the final (post-loop) chain segment, ending at the real head node. */
190
238
  function finishChain(
191
239
  w: ChainWalk, portEdge: GraphEdge, lastEdge: GraphEdge, segFirst: number, segs: GraphEdge[],
@@ -203,7 +251,8 @@ function finishChain(
203
251
  * collinear vnode run is split into spline-top + straight-middle + spline-bottom
204
252
  * via successive beginpath/endpath/routesplines calls, hugging the corridor.
205
253
  * `e` carries the real end ports (first beginpath, final endpath); the chain
206
- * edges drive the box geometry.
254
+ * edges drive the box geometry. A chain that stops at a vnode with no out edge
255
+ * is routed to it and dropped (closeDeadEnd): null, as for a failed route.
207
256
  * @see lib/dotgen/dotsplines.c:make_regular_edge (1771-1873 smode loop)
208
257
  */
209
258
  function routeChainSegmented(
@@ -222,6 +271,8 @@ function routeChainSegmented(
222
271
  segFirst = ei; smode = false;
223
272
  continue;
224
273
  }
274
+ // 16.1.1 walks on only while hn has an out edge (`ND_out(hn).size > 0`).
275
+ if (nodeOutSize(segs[ei].head) === 0) return closeDeadEnd(w, beginEdge, segs, ei, segFirst);
225
276
  si = false;
226
277
  w.boxes.push(maximalBbox(w.ctx, segs[ei].head, segs[ei], segs[ei + 1]));
227
278
  ei++;
@@ -229,70 +280,6 @@ function routeChainSegmented(
229
280
  return finishChain(w, endEdge, segs[ei], segFirst, segs) ? w.pts : null;
230
281
  }
231
282
 
232
- // ---------------------------------------------------------------------------
233
- // Hackflag views for an edge routed on another edge's chain
234
- // @see lib/dotgen/dotsplines.c:make_regular_edge (abs(rank diff) > 1)
235
- // ---------------------------------------------------------------------------
236
-
237
- /** A port copied by value, as C's struct assignment copies `port`. */
238
- function copyPort(p: Port): Port {
239
- return { ...p, p: { ...p.p } };
240
- }
241
-
242
- /**
243
- * C's `fwdedgea`: a copy of `e` from its rank-low end to the first vnode of the
244
- * chain, head port undefined at (0,0), VIRTUAL with `to_orig = e`. beginpath's
245
- * side-port clip reset therefore lands on `e` itself.
246
- */
247
- function hackflagBeginView(e: GraphEdge, back: boolean, firstVnode: Node): GraphEdge {
248
- const tailPort = back ? e.info.head_port : e.info.tail_port;
249
- return {
250
- ...e,
251
- tail: back ? e.head : e.tail,
252
- head: firstVnode,
253
- info: {
254
- ...e.info,
255
- tail_port: copyPort(tailPort),
256
- head_port: { ...copyPort(e.info.head_port), defined: false, p: { x: 0, y: 0 } },
257
- edge_type: VIRTUAL,
258
- to_orig: e,
259
- },
260
- } as GraphEdge;
261
- }
262
-
263
- /**
264
- * C's `fwdedgeb`: for a back edge, `makefwdedge(e)` (VIRTUAL, `to_orig = e`);
265
- * otherwise a plain struct copy of `e` that stays NORMAL, so endpath's
266
- * side-port clip reset lands on the copy and `e` keeps its head clip.
267
- */
268
- function hackflagEndView(e: GraphEdge, back: boolean): GraphEdge {
269
- if (back) return makeFwdEdge(e);
270
- return {
271
- ...e,
272
- info: { ...e.info, tail_port: copyPort(e.info.tail_port), head_port: copyPort(e.info.head_port) },
273
- } as GraphEdge;
274
- }
275
-
276
- /**
277
- * The edges that drive the chain's first beginpath and last endpath. A chain
278
- * owned by `e` itself is C's ordinary walk from the first to the last fast
279
- * edge. A chain owned by another edge means class2 merged `e` into it
280
- * (`merge_chain`), so `e` sits in ND_other and C's group loop hands the real
281
- * edge to make_regular_edge, which takes the hackflag branch: beginpath on
282
- * `fwdedgea`, endpath on `fwdedgeb`. Driving those calls with the owner's
283
- * segments reset the owner's clip flags instead of `e`'s (plantuml-ts 41).
284
- * @see lib/dotgen/dotsplines.c:make_regular_edge (hackflag)
285
- * @see lib/dotgen/class2.c:class2 (merge_chain, other_edge)
286
- */
287
- function chainEnds(e: GraphEdge, segs: GraphEdge[]): [GraphEdge, GraphEdge] {
288
- const first = segs[0];
289
- const last = segs[segs.length - 1];
290
- const orig = resolveOrigEdge(e);
291
- if (resolveOrigEdge(first) === orig) return [first, last];
292
- const back = (orig.head.info.rank ?? 0) < (orig.tail.info.rank ?? 0);
293
- return [hackflagBeginView(orig, back, first.head), hackflagEndView(orig, back)];
294
- }
295
-
296
283
  /** True when `e` runs forward across two or more ranks of a ranked graph. */
297
284
  function spansRanksForward(g: Graph, e: GraphEdge): boolean {
298
285
  const r = e.tail.info.rank;
@@ -305,9 +292,10 @@ function spansRanksForward(g: Graph, e: GraphEdge): boolean {
305
292
  * faithful pipeline (REGULAREDGE side boxes steer the port, routeSplines over
306
293
  * the chain; adjustregularpath inter-rank widening finally fires). Returns
307
294
  * control points in graphviz-internal y-up, null when the edge is not a
308
- * multi-rank chain, or 'lost' when the chain walk was attempted and failed
309
- * (completeregularpath / routesplines failure): C's make_regular_edge returns
310
- * with no spline and the edge is never routed again.
295
+ * multi-rank chain, or 'lost' when the chain walk was attempted and gave no
296
+ * spline (a completeregularpath / routesplines failure, or a chain that ends
297
+ * at a vnode with no out edge): C's make_regular_edge returns with no spline
298
+ * and the edge is never routed again.
311
299
  * @see lib/dotgen/dotsplines.c:make_regular_edge (hackflag forward path)
312
300
  */
313
301
  export function routeMultiRankEdgeFaithful(g: Graph, e: GraphEdge): Point[] | null | 'lost' {
@@ -321,11 +309,12 @@ export function routeMultiRankEdgeFaithful(g: Graph, e: GraphEdge): Point[] | nu
321
309
  if (line !== null) return line;
322
310
  }
323
311
  const segs = chainSegments(e);
324
- // Route only a COMPLETE chain (last segment reaches e.head). segs.length===1 is
325
- // valid (concentrate may merge the whole chain to a direct tail->head segment);
326
- // a chain ending at a virtual node is broken — bail, don't crash the loop.
312
+ // Route a COMPLETE chain (last segment reaches e.head). segs.length===1 is
313
+ // valid (concentrate may merge the whole chain to a direct tail->head segment).
314
+ // A chain that stops at a vnode with no out edge is routed too, to that dead
315
+ // end, as 16.1.1 does; one that stops at any other virtual node is declined.
327
316
  // @see dotsplines.c:make_regular_edge
328
- if (segs.length === 0 || segs[segs.length - 1].head !== e.head) return null;
317
+ if (segs.length === 0 || !chainEndsAt(segs, e.head)) return null;
329
318
  // C's make_regular_edge drives beginpath with the FIRST chain fast edge and
330
319
  // endpath with the LAST (each carries the orig's copied port, so a dyna
331
320
  // record port resolves toward the adjacent-rank vnode, not the far real
@@ -339,17 +328,19 @@ export function routeMultiRankEdgeFaithful(g: Graph, e: GraphEdge): Point[] | nu
339
328
  /**
340
329
  * The merge-bounded run owned by one collected entry: the entry followed by
341
330
  * `out.list[0]` successors while the head is a plain (non-merge) virtual node —
342
- * C make_regular_edge's chain walk. Returns null when the entry is NOT a
343
- * partial run (neither end at a splineMerge node): plain single-chain entries
344
- * belong to the caller's whole-chain routers.
331
+ * C make_regular_edge's chain walk. The run also stops at a vnode with no out
332
+ * edge, 16.1.1's dead end. Returns null when the entry is NOT a partial run
333
+ * (neither end at a splineMerge node): plain single-chain entries belong to
334
+ * the caller's whole-chain routers.
345
335
  * @see lib/dotgen/dotsplines.c:make_regular_edge (while !splineMerge(hn) walk)
336
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (16.1.1, 4f9ef1d9e)
346
337
  */
347
338
  function entryRunSegments(e: GraphEdge): GraphEdge[] | null {
348
339
  const segs: GraphEdge[] = [e];
349
340
  let hn = e.head;
350
341
  while ((hn.info.node_type ?? NORMAL) === VIRTUAL && !splineMerge(hn)) {
351
- const nxt = hn.info.out?.list[0];
352
- if (nxt === undefined) return null; // broken chain — leave to the caller
342
+ if (nodeOutSize(hn) === 0) break; // dead end: routeChainSegmented closes there
343
+ const nxt = hn.info.out!.list[0];
353
344
  segs.push(nxt);
354
345
  hn = nxt.head;
355
346
  }
@@ -369,8 +360,9 @@ function entryRunSegments(e: GraphEdge): GraphEdge[] | null {
369
360
  * orig) with the walk's final head node, exactly as C.
370
361
  *
371
362
  * Returns the resolved original edge when the entry was a partial run
372
- * (consumed — even if routing declined, so the caller never re-routes the
373
- * whole chain), or null when the entry is a plain full chain.
363
+ * (consumed — even if routing declined or the run stopped at a dead end, so
364
+ * the caller never re-routes the whole chain), or null when the entry is a
365
+ * plain full chain.
374
366
  * @see lib/dotgen/dotsplines.c:dot_splines_ (group loop), make_regular_edge
375
367
  */
376
368
  export function routeEntryRun(g: Graph, entry: GraphEdge): GraphEdge | null {
@@ -387,21 +379,35 @@ export function routeEntryRun(g: Graph, entry: GraphEdge): GraphEdge | null {
387
379
  * contains it (boxes run high-y to low-y). Label vnodes are anchored to the
388
380
  * box's right edge (center = box.ur.x + rw); plain vnodes are centred. This is
389
381
  * what aligns a flat-adj aux label vnode onto its spline so the label lands at
390
- * the dot position (DOT-12). @see lib/dotgen/dotsplines.c:recover_slack
382
+ * the dot position (DOT-12). @see lib/dotgen/dotsplines.c:recover_slack (resize_vn calls)
391
383
  */
392
384
  function resizeVnInBox(vn: Node, box: Box): void {
393
385
  if (vn.info.label != null) resizeVn(vn, box.ll.x, box.ur.x, box.ur.x + vn.info.rw);
394
386
  else resizeVn(vn, box.ll.x, (box.ll.x + box.ur.x) / 2, box.ur.x);
395
387
  }
396
388
 
397
- function recoverSlack(segs: GraphEdge[], P: Path): void {
389
+ /**
390
+ * Walk the routed segment's chain vnodes (`segs[i].head`, C's
391
+ * `vn = aghead(ND_out(vn).list[0])` step) and resize each into its box. The
392
+ * walk ends at a vnode with no out edge, whether or not a box reached it:
393
+ * 16.1.1's two `ND_out(vn).size == 0` exits, where 16.1.0 stepped through a
394
+ * NULL `list[0]` (upstream issue 2765). Exported for tests only: not part of
395
+ * the package's entry points.
396
+ * @see lib/dotgen/dotsplines.c:recover_slack (16.1.1, f3da7c569)
397
+ */
398
+ export function recoverSlack(segs: GraphEdge[], P: Path): void {
398
399
  let b = 0; // skip first rank box
399
400
  for (let i = 0; i < segs.length; i++) {
400
401
  const vn = segs[i].head;
401
- if ((vn.info.node_type ?? NORMAL) !== VIRTUAL || splineMerge(vn)) break;
402
+ if (!isChainVirtual(vn)) break;
402
403
  while (b < P.nbox && P.boxes[b].ll.y > vn.info.coord.y) b++;
403
404
  if (b >= P.nbox) break;
404
- if (P.boxes[b].ur.y >= vn.info.coord.y) resizeVnInBox(vn, P.boxes[b]);
405
+ if (P.boxes[b].ur.y < vn.info.coord.y) {
406
+ if (nodeOutSize(vn) === 0) break;
407
+ continue;
408
+ }
409
+ resizeVnInBox(vn, P.boxes[b]);
410
+ if (nodeOutSize(vn) === 0) break;
405
411
  }
406
412
  }
407
413
 
@@ -427,39 +433,17 @@ function backChainSegments(e: GraphEdge): GraphEdge[] {
427
433
  }
428
434
 
429
435
  /**
430
- * Forward view of any edge (C `makefwdedge`): tail/head swapped when the edge
431
- * runs high→low rank (a back edge), fresh portless ends. `beginPath`/`endPath`
432
- * read `e.tail`/`e.head`, so the chain must be driven by an edge that runs
433
- * low→high rank. Sets `to_orig`/`edge_type=VIRTUAL` so `clipAndInstall`→
434
- * `newSpline` installs the spline on the ORIGINAL edge (its `to_orig` loop) and
435
- * the post-routing `swapSpline` pass reverses it back to tail→head. Shares
436
- * `attrs`/`root`/`to_virt` with `e`. Consumed by T3 for parallel back-members.
437
- * @see lib/dotgen/dotsplines.c:makefwdedge
438
- * @see lib/common/splines.c:clip_and_install (to_orig install loop)
436
+ * True when routeBackEdge routes the collected chain: one of two or more
437
+ * segments that reaches `end` (the back edge's tail), or one of any length
438
+ * that stops at a dead end, which 16.1.1 routes to and drops.
439
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (16.1.1, 4f9ef1d9e)
439
440
  */
440
- export function makeFwdEdge(e: GraphEdge): GraphEdge {
441
- const back = (e.head.info.rank ?? 0) < (e.tail.info.rank ?? 0);
442
- const [tail, head] = back ? [e.head, e.tail] : [e.tail, e.head];
443
- return {
444
- ...e,
445
- tail,
446
- head,
447
- info: {
448
- ...e.info,
449
- // C makefwdedge SWAPS the ports (does not strip them): a back edge keeps
450
- // its corner ports across the forward view so make_regular_edge curls it
451
- // (e.g. #241_0 aux back-edge clone sw/se → size 7). Stripping to an empty
452
- // Center port straightened every port-bearing back edge (size 4).
453
- // @see lib/dotgen/dotsplines.c:makefwdedge (ED_tail_port(new)=ED_head_port(old))
454
- tail_port: e.info.head_port ?? makePort(),
455
- head_port: e.info.tail_port ?? makePort(),
456
- to_orig: e,
457
- edge_type: VIRTUAL,
458
- },
459
- } as GraphEdge;
441
+ function isRoutableBackChain(segs: GraphEdge[], end: Node): boolean {
442
+ if (segs.length === 0) return false;
443
+ const tip = segs[segs.length - 1].head;
444
+ return tip === end ? segs.length >= 2 : isChainDeadEnd(tip);
460
445
  }
461
446
 
462
-
463
447
  /**
464
448
  * Route a multi-rank back-edge via its virtual node chain, mirroring C exactly:
465
449
  * make_regular_edge routes the makefwdedge (forward) view, clip_and_install
@@ -471,11 +455,13 @@ export function makeFwdEdge(e: GraphEdge): GraphEdge {
471
455
  * opposite parameter end), landing the 0.5-tolerance crossing ~0.26-0.33 off
472
456
  * (1644, dfa family). clipAndInstall resolves the spline onto `e` via the
473
457
  * fwdEdge's to_orig and gates arrows by ED_dir, so this also drops the bespoke
474
- * reverse/arrow code. @see lib/dotgen/dotsplines.c:make_regular_edge (hackflag)
458
+ * reverse/arrow code. A chain that stops at a vnode with no out edge is routed
459
+ * to that dead end and the edge is lost, as 16.1.1 does.
460
+ * @see lib/dotgen/dotsplines.c:make_regular_edge (hackflag)
475
461
  */
476
462
  export function routeBackEdge(e: GraphEdge, _tailBox: NodeBox, _headBox: NodeBox, g: Graph): void {
477
463
  const segs = backChainSegments(e);
478
- if (segs.length < 2 || segs[segs.length - 1].head !== e.tail) return;
464
+ if (!isRoutableBackChain(segs, e.tail)) return;
479
465
  const fwdEdge = makeFwdEdge(e);
480
466
  // C's make_regular_edge routes the collected FAST SEGMENT view: beginpath's
481
467
  // edge head is the adjacent chain vnode, so a dyna record port resolves
@@ -43,7 +43,7 @@ import { edgeType } from './splines.js';
43
43
  import { addBox } from '../../common/splines-path-shared.js';
44
44
  import { TOP, BOTTOM, REGULAREDGE } from '../../common/splines-constants.js';
45
45
  import { VIRTUAL, NORMAL } from './fastgr.js';
46
- import { neighbor, topBound, botBound, nodeType, splineMerge } from './splines-route.js';
46
+ import { neighbor, topBound, botBound, nodeType, splineMerge, nodeOutSize } from './splines-route.js';
47
47
  import { getSplineBounds, rankHt } from './edge-route-rank.js';
48
48
  import { graphRanksep } from './position-aux.js';
49
49
 
@@ -90,10 +90,12 @@ function isLabeledVirtual(n: Node): boolean {
90
90
  return nodeType(n) === VIRTUAL && n.info.label != null;
91
91
  }
92
92
 
93
- /** Tail/head clusters behind node n: its own cluster when NORMAL, else the
94
- * original edge's endpoint clusters. @see cl_bound (dotsplines.c:2135-2140) */
93
+ /** Tail/head clusters behind node n: its own cluster when NORMAL or when it
94
+ * has no out edge (a virtual node concentrate orphaned, upstream issue 2765),
95
+ * else the original edge's endpoint clusters.
96
+ * @see lib/dotgen/dotsplines.c:cl_bound (16.1.1, f8e3f2100) */
95
97
  function endpointClusters(n: Node): [Graph | undefined, Graph | undefined] {
96
- if (nodeType(n) === NORMAL) return [n.info.clust, n.info.clust];
98
+ if (nodeType(n) === NORMAL || nodeOutSize(n) === 0) return [n.info.clust, n.info.clust];
97
99
  const orig = n.info.out?.list[0]?.info.to_orig;
98
100
  return [orig?.tail.info.clust, orig?.head.info.clust];
99
101
  }
@@ -281,9 +283,22 @@ function pathBoundsReady(first: Edge, last: Edge): boolean {
281
283
  && !boundMissing(botBound(last, -1)) && !boundMissing(botBound(last, 1));
282
284
  }
283
285
 
284
- /** Grow rank boxes (even slots) / inter-rank boxes (odd) to a minimum width. */
286
+ /**
287
+ * Grow rank boxes (even slots) / inter-rank boxes (odd) to a minimum width.
288
+ *
289
+ * C runs `fb - 1 .. lb` whatever `P->nbox` is: when `add_box` dropped boxes,
290
+ * the loop reaches slots at or past `nbox` of the array dot_splines_
291
+ * preallocates (dotsplines.c:338) and widens them. Those writes are dead:
292
+ * every reader of a path's boxes stops at `nbox` (routesplines_, checkpath,
293
+ * printpath, recover_slack, this function's second loop), and `add_box`
294
+ * overwrites slot `nbox` before it counts it. The port's array holds no such
295
+ * slot (or a stale reference to a box that is live elsewhere, which C's
296
+ * struct copies cannot reach), so it skips them.
297
+ * @see lib/dotgen/dotsplines.c:adjustregularpath (first loop)
298
+ */
285
299
  function widenPathBoxes(P: Path, fb: number, lb: number): void {
286
300
  for (let i = fb - 1; i < lb + 1; i++) {
301
+ if (i >= P.nbox) continue;
287
302
  const bp = P.boxes[i];
288
303
  const even = (i - fb) % 2 === 0;
289
304
  const tooNarrow = even ? bp.ll.x >= bp.ur.x : bp.ll.x + MINW > bp.ur.x;