@knowvah/dot-engine 2.8.1 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/dist/common/graph-init.d.ts.map +1 -1
  2. package/dist/common/poly-gencode.d.ts.map +1 -1
  3. package/dist/common/poly-init.d.ts +3 -2
  4. package/dist/common/poly-init.d.ts.map +1 -1
  5. package/dist/common/safefile.d.ts +23 -0
  6. package/dist/common/safefile.d.ts.map +1 -0
  7. package/dist/common/shapes.d.ts +6 -6
  8. package/dist/common/shapes.d.ts.map +1 -1
  9. package/dist/gvc/device.d.ts.map +1 -1
  10. package/dist/gvc/image-type.d.ts +41 -0
  11. package/dist/gvc/image-type.d.ts.map +1 -0
  12. package/dist/gvc/render-usershape.d.ts +8 -0
  13. package/dist/gvc/render-usershape.d.ts.map +1 -1
  14. package/dist/gvc/usershape.d.ts +23 -1
  15. package/dist/gvc/usershape.d.ts.map +1 -1
  16. package/dist/index.js +8328 -6979
  17. package/dist/index.js.map +4 -4
  18. package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts +118 -0
  19. package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts.map +1 -0
  20. package/dist/layout/neato/__fixtures__/stress-models.d.ts +39 -0
  21. package/dist/layout/neato/__fixtures__/stress-models.d.ts.map +1 -0
  22. package/dist/layout/neato/circuit.d.ts +10 -0
  23. package/dist/layout/neato/circuit.d.ts.map +1 -0
  24. package/dist/layout/neato/init.d.ts +3 -2
  25. package/dist/layout/neato/init.d.ts.map +1 -1
  26. package/dist/layout/neato/ipsep-opts.d.ts +19 -0
  27. package/dist/layout/neato/ipsep-opts.d.ts.map +1 -0
  28. package/dist/layout/neato/lu.d.ts +35 -0
  29. package/dist/layout/neato/lu.d.ts.map +1 -0
  30. package/dist/layout/neato/matinv.d.ts +8 -0
  31. package/dist/layout/neato/matinv.d.ts.map +1 -0
  32. package/dist/layout/neato/quad-prog-vpsc-overlap.d.ts +35 -0
  33. package/dist/layout/neato/quad-prog-vpsc-overlap.d.ts.map +1 -0
  34. package/dist/layout/neato/quad-prog-vpsc.d.ts +110 -0
  35. package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -0
  36. package/dist/layout/neato/start.d.ts +5 -4
  37. package/dist/layout/neato/start.d.ts.map +1 -1
  38. package/dist/layout/neato/stress-cola.d.ts +65 -0
  39. package/dist/layout/neato/stress-cola.d.ts.map +1 -0
  40. package/dist/layout/neato/stress-kernel.d.ts +0 -2
  41. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  42. package/dist/layout/neato/stress-models.d.ts +48 -0
  43. package/dist/layout/neato/stress-models.d.ts.map +1 -0
  44. package/dist/layout/neato/vpsc-adjust.d.ts +7 -8
  45. package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
  46. package/dist/render/color-resolve.d.ts +14 -0
  47. package/dist/render/color-resolve.d.ts.map +1 -1
  48. package/dist/render/dot/edge-draw.d.ts.map +1 -1
  49. package/dist/render/svg-arrow-ops.d.ts +21 -4
  50. package/dist/render/svg-arrow-ops.d.ts.map +1 -1
  51. package/dist/render/svg-edge-arrows.d.ts +3 -3
  52. package/dist/render/svg-edge-arrows.d.ts.map +1 -1
  53. package/dist/render/svg-helpers.d.ts +1 -1
  54. package/dist/render/svg-helpers.d.ts.map +1 -1
  55. package/dist/render/svg.d.ts.map +1 -1
  56. package/dist/render.js +8318 -6969
  57. package/dist/render.js.map +4 -4
  58. package/package.json +1 -1
  59. package/src/common/graph-init.ts +4 -2
  60. package/src/common/poly-gencode.ts +2 -1
  61. package/src/common/poly-init.ts +21 -12
  62. package/src/common/safefile.ts +74 -0
  63. package/src/common/shapes.ts +43 -22
  64. package/src/gvc/__fixtures__/p7/colors/98-point.gv +1 -0
  65. package/src/gvc/__fixtures__/p7/colors/98-point.json +54 -0
  66. package/src/gvc/__fixtures__/p7/colors/98-point.json.stderr +1 -0
  67. package/src/gvc/__fixtures__/p7/colors/98-point.svg +17 -0
  68. package/src/gvc/__fixtures__/p7/colors/98-point.svg.stderr +1 -0
  69. package/src/gvc/__fixtures__/p7/colors/98-point.xdot +13 -0
  70. package/src/gvc/__fixtures__/p7/colors/98-point.xdot.stderr +1 -0
  71. package/src/gvc/__fixtures__/p7/colors/99-edge-color.gv +1 -0
  72. package/src/gvc/__fixtures__/p7/colors/99-edge-color.json +150 -0
  73. package/src/gvc/__fixtures__/p7/colors/99-edge-color.json.stderr +1 -0
  74. package/src/gvc/__fixtures__/p7/colors/99-edge-color.svg +30 -0
  75. package/src/gvc/__fixtures__/p7/colors/99-edge-color.svg.stderr +1 -0
  76. package/src/gvc/__fixtures__/p7/colors/99-edge-color.xdot +22 -0
  77. package/src/gvc/__fixtures__/p7/colors/99-edge-color.xdot.stderr +1 -0
  78. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.gv +1 -0
  79. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.json +149 -0
  80. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.json.stderr +0 -0
  81. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.svg +30 -0
  82. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.svg.stderr +0 -0
  83. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.xdot +21 -0
  84. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.xdot.stderr +0 -0
  85. package/src/gvc/__fixtures__/p7/colors/99-edge.gv +1 -0
  86. package/src/gvc/__fixtures__/p7/colors/99-edge.json +149 -0
  87. package/src/gvc/__fixtures__/p7/colors/99-edge.json.stderr +1 -0
  88. package/src/gvc/__fixtures__/p7/colors/99-edge.svg +30 -0
  89. package/src/gvc/__fixtures__/p7/colors/99-edge.svg.stderr +1 -0
  90. package/src/gvc/__fixtures__/p7/colors/99-edge.xdot +21 -0
  91. package/src/gvc/__fixtures__/p7/colors/99-edge.xdot.stderr +1 -0
  92. package/src/gvc/__fixtures__/p7/images/100-rotate.gv +1 -0
  93. package/src/gvc/__fixtures__/p7/images/100-rotate.svg +19 -0
  94. package/src/gvc/__fixtures__/p7/images/100-rotate.svg.stderr +0 -0
  95. package/src/gvc/__fixtures__/p7/images/101-bad.cmapx +2 -0
  96. package/src/gvc/__fixtures__/p7/images/101-bad.cmapx.stderr +2 -0
  97. package/src/gvc/__fixtures__/p7/images/101-bad.dot +8 -0
  98. package/src/gvc/__fixtures__/p7/images/101-bad.dot.stderr +2 -0
  99. package/src/gvc/__fixtures__/p7/images/101-bad.gv +1 -0
  100. package/src/gvc/__fixtures__/p7/images/101-bad.json +68 -0
  101. package/src/gvc/__fixtures__/p7/images/101-bad.json.stderr +2 -0
  102. package/src/gvc/__fixtures__/p7/images/101-bad.plain +3 -0
  103. package/src/gvc/__fixtures__/p7/images/101-bad.plain.stderr +2 -0
  104. package/src/gvc/__fixtures__/p7/images/101-bad.svg +18 -0
  105. package/src/gvc/__fixtures__/p7/images/101-bad.svg.stderr +2 -0
  106. package/src/gvc/__fixtures__/p7/images/101-bad.xdot +13 -0
  107. package/src/gvc/__fixtures__/p7/images/101-bad.xdot.stderr +2 -0
  108. package/src/gvc/__fixtures__/p7/images/101-gif.cmapx +2 -0
  109. package/src/gvc/__fixtures__/p7/images/101-gif.cmapx.stderr +0 -0
  110. package/src/gvc/__fixtures__/p7/images/101-gif.dot +8 -0
  111. package/src/gvc/__fixtures__/p7/images/101-gif.dot.stderr +0 -0
  112. package/src/gvc/__fixtures__/p7/images/101-gif.gv +1 -0
  113. package/src/gvc/__fixtures__/p7/images/101-gif.json +70 -0
  114. package/src/gvc/__fixtures__/p7/images/101-gif.json.stderr +1 -0
  115. package/src/gvc/__fixtures__/p7/images/101-gif.plain +3 -0
  116. package/src/gvc/__fixtures__/p7/images/101-gif.plain.stderr +0 -0
  117. package/src/gvc/__fixtures__/p7/images/101-gif.svg +19 -0
  118. package/src/gvc/__fixtures__/p7/images/101-gif.svg.stderr +0 -0
  119. package/src/gvc/__fixtures__/p7/images/101-gif.xdot +13 -0
  120. package/src/gvc/__fixtures__/p7/images/101-gif.xdot.stderr +0 -0
  121. package/src/gvc/__fixtures__/p7/images/101-jpg.cmapx +2 -0
  122. package/src/gvc/__fixtures__/p7/images/101-jpg.cmapx.stderr +0 -0
  123. package/src/gvc/__fixtures__/p7/images/101-jpg.dot +8 -0
  124. package/src/gvc/__fixtures__/p7/images/101-jpg.dot.stderr +0 -0
  125. package/src/gvc/__fixtures__/p7/images/101-jpg.gv +1 -0
  126. package/src/gvc/__fixtures__/p7/images/101-jpg.json +70 -0
  127. package/src/gvc/__fixtures__/p7/images/101-jpg.json.stderr +1 -0
  128. package/src/gvc/__fixtures__/p7/images/101-jpg.plain +3 -0
  129. package/src/gvc/__fixtures__/p7/images/101-jpg.plain.stderr +0 -0
  130. package/src/gvc/__fixtures__/p7/images/101-jpg.svg +19 -0
  131. package/src/gvc/__fixtures__/p7/images/101-jpg.svg.stderr +0 -0
  132. package/src/gvc/__fixtures__/p7/images/101-jpg.xdot +13 -0
  133. package/src/gvc/__fixtures__/p7/images/101-jpg.xdot.stderr +0 -0
  134. package/src/gvc/__fixtures__/p7/images/101-png.cmapx +2 -0
  135. package/src/gvc/__fixtures__/p7/images/101-png.cmapx.stderr +0 -0
  136. package/src/gvc/__fixtures__/p7/images/101-png.dot +8 -0
  137. package/src/gvc/__fixtures__/p7/images/101-png.dot.stderr +0 -0
  138. package/src/gvc/__fixtures__/p7/images/101-png.gv +1 -0
  139. package/src/gvc/__fixtures__/p7/images/101-png.json +70 -0
  140. package/src/gvc/__fixtures__/p7/images/101-png.json.stderr +1 -0
  141. package/src/gvc/__fixtures__/p7/images/101-png.plain +3 -0
  142. package/src/gvc/__fixtures__/p7/images/101-png.plain.stderr +0 -0
  143. package/src/gvc/__fixtures__/p7/images/101-png.svg +19 -0
  144. package/src/gvc/__fixtures__/p7/images/101-png.svg.stderr +0 -0
  145. package/src/gvc/__fixtures__/p7/images/101-png.xdot +13 -0
  146. package/src/gvc/__fixtures__/p7/images/101-png.xdot.stderr +0 -0
  147. package/src/gvc/__fixtures__/p7/images/101-svg.cmapx +2 -0
  148. package/src/gvc/__fixtures__/p7/images/101-svg.cmapx.stderr +0 -0
  149. package/src/gvc/__fixtures__/p7/images/101-svg.dot +8 -0
  150. package/src/gvc/__fixtures__/p7/images/101-svg.dot.stderr +0 -0
  151. package/src/gvc/__fixtures__/p7/images/101-svg.gv +1 -0
  152. package/src/gvc/__fixtures__/p7/images/101-svg.json +70 -0
  153. package/src/gvc/__fixtures__/p7/images/101-svg.json.stderr +1 -0
  154. package/src/gvc/__fixtures__/p7/images/101-svg.plain +3 -0
  155. package/src/gvc/__fixtures__/p7/images/101-svg.plain.stderr +0 -0
  156. package/src/gvc/__fixtures__/p7/images/101-svg.svg +19 -0
  157. package/src/gvc/__fixtures__/p7/images/101-svg.svg.stderr +0 -0
  158. package/src/gvc/__fixtures__/p7/images/101-svg.xdot +13 -0
  159. package/src/gvc/__fixtures__/p7/images/101-svg.xdot.stderr +0 -0
  160. package/src/gvc/__fixtures__/p7/images/101-svgbare.cmapx +2 -0
  161. package/src/gvc/__fixtures__/p7/images/101-svgbare.cmapx.stderr +2 -0
  162. package/src/gvc/__fixtures__/p7/images/101-svgbare.dot +8 -0
  163. package/src/gvc/__fixtures__/p7/images/101-svgbare.dot.stderr +2 -0
  164. package/src/gvc/__fixtures__/p7/images/101-svgbare.gv +1 -0
  165. package/src/gvc/__fixtures__/p7/images/101-svgbare.json +68 -0
  166. package/src/gvc/__fixtures__/p7/images/101-svgbare.json.stderr +2 -0
  167. package/src/gvc/__fixtures__/p7/images/101-svgbare.plain +3 -0
  168. package/src/gvc/__fixtures__/p7/images/101-svgbare.plain.stderr +2 -0
  169. package/src/gvc/__fixtures__/p7/images/101-svgbare.svg +18 -0
  170. package/src/gvc/__fixtures__/p7/images/101-svgbare.svg.stderr +2 -0
  171. package/src/gvc/__fixtures__/p7/images/101-svgbare.xdot +13 -0
  172. package/src/gvc/__fixtures__/p7/images/101-svgbare.xdot.stderr +2 -0
  173. package/src/gvc/__fixtures__/p7/images/102-ip-abs.gv +1 -0
  174. package/src/gvc/__fixtures__/p7/images/102-ip-abs.svg +18 -0
  175. package/src/gvc/__fixtures__/p7/images/102-ip-abs.svg.stderr +2 -0
  176. package/src/gvc/__fixtures__/p7/images/102-ip-abs.xdot +14 -0
  177. package/src/gvc/__fixtures__/p7/images/102-ip-abs.xdot.stderr +2 -0
  178. package/src/gvc/__fixtures__/p7/images/102-ip-found.gv +1 -0
  179. package/src/gvc/__fixtures__/p7/images/102-ip-found.svg +19 -0
  180. package/src/gvc/__fixtures__/p7/images/102-ip-found.svg.stderr +0 -0
  181. package/src/gvc/__fixtures__/p7/images/102-ip-found.xdot +14 -0
  182. package/src/gvc/__fixtures__/p7/images/102-ip-found.xdot.stderr +0 -0
  183. package/src/gvc/__fixtures__/p7/images/102-ip-missing.gv +1 -0
  184. package/src/gvc/__fixtures__/p7/images/102-ip-missing.svg +18 -0
  185. package/src/gvc/__fixtures__/p7/images/102-ip-missing.svg.stderr +2 -0
  186. package/src/gvc/__fixtures__/p7/images/102-ip-missing.xdot +14 -0
  187. package/src/gvc/__fixtures__/p7/images/102-ip-missing.xdot.stderr +2 -0
  188. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.gv +1 -0
  189. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.svg +18 -0
  190. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.svg.stderr +2 -0
  191. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.xdot +15 -0
  192. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.xdot.stderr +2 -0
  193. package/src/gvc/__fixtures__/p7/images/102-ip-two.gv +1 -0
  194. package/src/gvc/__fixtures__/p7/images/102-ip-two.svg +19 -0
  195. package/src/gvc/__fixtures__/p7/images/102-ip-two.svg.stderr +0 -0
  196. package/src/gvc/__fixtures__/p7/images/102-ip-two.xdot +14 -0
  197. package/src/gvc/__fixtures__/p7/images/102-ip-two.xdot.stderr +0 -0
  198. package/src/gvc/__fixtures__/p7/images/97-custom.gv +1 -0
  199. package/src/gvc/__fixtures__/p7/images/97-custom.svg +18 -0
  200. package/src/gvc/__fixtures__/p7/images/97-custom.svg.stderr +1 -0
  201. package/src/gvc/__fixtures__/p7/images/97-custom.xdot +13 -0
  202. package/src/gvc/__fixtures__/p7/images/97-custom.xdot.stderr +1 -0
  203. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.gv +1 -0
  204. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.svg +19 -0
  205. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.svg.stderr +1 -0
  206. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.xdot +14 -0
  207. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.xdot.stderr +1 -0
  208. package/src/gvc/__fixtures__/p7/images/bad.png +1 -0
  209. package/src/gvc/__fixtures__/p7/images/d/r.png +0 -0
  210. package/src/gvc/__fixtures__/p7/images/d2/r.png +0 -0
  211. package/src/gvc/__fixtures__/p7/images/g.gif +0 -0
  212. package/src/gvc/__fixtures__/p7/images/graphs-val_val.gv +10 -0
  213. package/src/gvc/__fixtures__/p7/images/graphs-val_val.svg +25 -0
  214. package/src/gvc/__fixtures__/p7/images/graphs-val_val.svg.stderr +3 -0
  215. package/src/gvc/__fixtures__/p7/images/graphs-val_val.xdot +30 -0
  216. package/src/gvc/__fixtures__/p7/images/graphs-val_val.xdot.stderr +3 -0
  217. package/src/gvc/__fixtures__/p7/images/j.jpg +0 -0
  218. package/src/gvc/__fixtures__/p7/images/r.png +0 -0
  219. package/src/gvc/__fixtures__/p7/images/s.svg +2 -0
  220. package/src/gvc/__fixtures__/p7/images/sb.svg +1 -0
  221. package/src/gvc/__fixtures__/p7/images/t.png +0 -0
  222. package/src/gvc/__fixtures__/p7/regen.sh +23 -0
  223. package/src/gvc/device.ts +11 -4
  224. package/src/gvc/image-type.ts +122 -0
  225. package/src/gvc/render-usershape.ts +52 -1
  226. package/src/gvc/usershape.ts +40 -1
  227. package/src/layout/neato/__fixtures__/ipsep/big-dired.gv +243 -0
  228. package/src/layout/neato/__fixtures__/ipsep/big-dired.trace +55 -0
  229. package/src/layout/neato/__fixtures__/ipsep/big-dired.xdot +1832 -0
  230. package/src/layout/neato/__fixtures__/ipsep/big-dired.xdot.stderr +0 -0
  231. package/src/layout/neato/__fixtures__/ipsep/cluster.gv +1 -0
  232. package/src/layout/neato/__fixtures__/ipsep/cluster.trace +95 -0
  233. package/src/layout/neato/__fixtures__/ipsep/cluster.xdot +58 -0
  234. package/src/layout/neato/__fixtures__/ipsep/cluster.xdot.stderr +0 -0
  235. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.gv +1 -0
  236. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.trace +40 -0
  237. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.xdot +72 -0
  238. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.xdot.stderr +0 -0
  239. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.gv +1 -0
  240. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.trace +43 -0
  241. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.xdot +72 -0
  242. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.xdot.stderr +0 -0
  243. package/src/layout/neato/__fixtures__/ipsep/dired-hier.gv +1 -0
  244. package/src/layout/neato/__fixtures__/ipsep/dired-hier.trace +43 -0
  245. package/src/layout/neato/__fixtures__/ipsep/dired-hier.xdot +71 -0
  246. package/src/layout/neato/__fixtures__/ipsep/dired-hier.xdot.stderr +0 -0
  247. package/src/layout/neato/__fixtures__/ipsep/dired-true.gv +1 -0
  248. package/src/layout/neato/__fixtures__/ipsep/dired-true.trace +51 -0
  249. package/src/layout/neato/__fixtures__/ipsep/dired-true.xdot +71 -0
  250. package/src/layout/neato/__fixtures__/ipsep/dired-true.xdot.stderr +0 -0
  251. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.gv +1 -0
  252. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.trace +41 -0
  253. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +77 -0
  254. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot.stderr +0 -0
  255. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.gv +1 -0
  256. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.trace +41 -0
  257. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +68 -0
  258. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot.stderr +0 -0
  259. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.gv +1 -0
  260. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.trace +42 -0
  261. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +110 -0
  262. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot.stderr +0 -0
  263. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.gv +1 -0
  264. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.trace +49 -0
  265. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +108 -0
  266. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot.stderr +0 -0
  267. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.gv +1 -0
  268. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.trace +43 -0
  269. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +83 -0
  270. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot.stderr +0 -0
  271. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.gv +1 -0
  272. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.trace +49 -0
  273. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +48 -0
  274. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot.stderr +0 -0
  275. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.gv +1 -0
  276. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.trace +45 -0
  277. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +47 -0
  278. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot.stderr +0 -0
  279. package/src/layout/neato/__fixtures__/ipsep/len-dired.gv +1 -0
  280. package/src/layout/neato/__fixtures__/ipsep/len-dired.trace +44 -0
  281. package/src/layout/neato/__fixtures__/ipsep/len-dired.xdot +66 -0
  282. package/src/layout/neato/__fixtures__/ipsep/len-dired.xdot.stderr +0 -0
  283. package/src/layout/neato/__fixtures__/ipsep/model-circuit.gv +1 -0
  284. package/src/layout/neato/__fixtures__/ipsep/model-circuit.trace +46 -0
  285. package/src/layout/neato/__fixtures__/ipsep/model-circuit.xdot +83 -0
  286. package/src/layout/neato/__fixtures__/ipsep/model-circuit.xdot.stderr +0 -0
  287. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.gv +1 -0
  288. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.trace +52 -0
  289. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.xdot +72 -0
  290. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.xdot.stderr +0 -0
  291. package/src/layout/neato/__fixtures__/ipsep/model-mds.gv +1 -0
  292. package/src/layout/neato/__fixtures__/ipsep/model-mds.trace +52 -0
  293. package/src/layout/neato/__fixtures__/ipsep/model-mds.xdot +83 -0
  294. package/src/layout/neato/__fixtures__/ipsep/model-mds.xdot.stderr +2 -0
  295. package/src/layout/neato/__fixtures__/ipsep/model-subset.gv +1 -0
  296. package/src/layout/neato/__fixtures__/ipsep/model-subset.trace +49 -0
  297. package/src/layout/neato/__fixtures__/ipsep/model-subset.xdot +83 -0
  298. package/src/layout/neato/__fixtures__/ipsep/model-subset.xdot.stderr +0 -0
  299. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.gv +1 -0
  300. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.trace +211 -0
  301. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.xdot +60 -0
  302. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.xdot.stderr +0 -0
  303. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.gv +1 -0
  304. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.trace +50 -0
  305. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.xdot +60 -0
  306. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.xdot.stderr +0 -0
  307. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.gv +1 -0
  308. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.trace +51 -0
  309. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.xdot +72 -0
  310. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.xdot.stderr +0 -0
  311. package/src/layout/neato/__fixtures__/ipsep/start-self.gv +1 -0
  312. package/src/layout/neato/__fixtures__/ipsep/start-self.trace +43 -0
  313. package/src/layout/neato/__fixtures__/ipsep/start-self.xdot +84 -0
  314. package/src/layout/neato/__fixtures__/ipsep/start-self.xdot.stderr +0 -0
  315. package/src/layout/neato/__fixtures__/quad-prog-vpsc.ts +109 -0
  316. package/src/layout/neato/__fixtures__/stress-models.ts +64 -0
  317. package/src/layout/neato/circuit.ts +31 -0
  318. package/src/layout/neato/index.ts +2 -2
  319. package/src/layout/neato/init.ts +25 -34
  320. package/src/layout/neato/ipsep-opts.ts +158 -0
  321. package/src/layout/neato/lu.ts +189 -0
  322. package/src/layout/neato/matinv.ts +37 -0
  323. package/src/layout/neato/quad-prog-vpsc-overlap.ts +365 -0
  324. package/src/layout/neato/quad-prog-vpsc.ts +416 -0
  325. package/src/layout/neato/start.ts +9 -24
  326. package/src/layout/neato/stress-cola.ts +497 -0
  327. package/src/layout/neato/stress-kernel.ts +1 -17
  328. package/src/layout/neato/stress-models.ts +212 -0
  329. package/src/layout/neato/vpsc-adjust.ts +35 -66
  330. package/src/render/color-resolve.ts +25 -2
  331. package/src/render/dot/edge-draw.ts +7 -4
  332. package/src/render/svg-arrow-ops.ts +35 -19
  333. package/src/render/svg-edge-arrows.ts +7 -6
  334. package/src/render/svg-helpers.ts +19 -11
  335. package/src/render/svg.ts +15 -3
@@ -32,6 +32,9 @@ import { setEdgeLen } from './edge-len.js';
32
32
  import { makeGraphDataC, graphHasLen } from './make-graph-data.js';
33
33
  import type { DirectedVtxData } from './opt-arrangement.js';
34
34
  import { stressMajorizationWithHierarchy } from './constrained-majorization.js';
35
+ import { stressMajorizationCola } from './stress-cola.js';
36
+ import { ipsepOptions } from './ipsep-opts.js';
37
+ import { AM_NONE, type AdjustData } from './fdp-adjust.js';
35
38
  import { agerr } from '../../common/agerr.js';
36
39
 
37
40
  export { makeGraphDataC, graphHasLen, checkStart };
@@ -108,10 +111,6 @@ export function neatoInitNode(n: Node, dim = DFLT_DIM): void {
108
111
  if (!n.info.height && !plainShaped) n.info.height = 0.5;
109
112
  }
110
113
 
111
- // ---------------------------------------------------------------------------
112
- // userPos
113
- // ---------------------------------------------------------------------------
114
-
115
114
  /**
116
115
  * Seed a node's initial position from its `pos=` attribute (C's P_SET),
117
116
  * mirroring user_pos. Sets info.pos + info.posSet so hasPos is true and neato
@@ -137,10 +136,6 @@ export function userPos(n: Node): boolean {
137
136
  return true;
138
137
  }
139
138
 
140
- // ---------------------------------------------------------------------------
141
- // setSeed helpers
142
- // ---------------------------------------------------------------------------
143
-
144
139
  /**
145
140
  * Classify the first character of `p` as 'alpha', 'digit', or 'other'.
146
141
  *
@@ -203,10 +198,6 @@ export function setSeed(
203
198
  return defaultMode;
204
199
  }
205
200
 
206
- // ---------------------------------------------------------------------------
207
- // buildVtxData helpers
208
- // ---------------------------------------------------------------------------
209
-
210
201
  /**
211
202
  * Assign sequential IDs to all nodes and return them in insertion order.
212
203
  *
@@ -279,10 +270,6 @@ export function buildVtxData(g: Graph): VtxData[] {
279
270
  return vtx;
280
271
  }
281
272
 
282
- // ---------------------------------------------------------------------------
283
- // buildDCoords / writeBackCoords
284
- // ---------------------------------------------------------------------------
285
-
286
273
  /**
287
274
  * Copy node positions from `n.info.pos` into per-axis Float64Array.
288
275
  *
@@ -312,10 +299,6 @@ export function writeBackCoords(nodeList: Node[], dCoords: Float64Array[], dim:
312
299
  }
313
300
  }
314
301
 
315
- // ---------------------------------------------------------------------------
316
- // mapModelToStress
317
- // ---------------------------------------------------------------------------
318
-
319
302
  /**
320
303
  * Map init.ts model constants to stress.ts model constants.
321
304
  * Both use the same numeric values but are distinct exports.
@@ -327,10 +310,6 @@ export function mapModelToStress(model: number): number {
327
310
  return 0;
328
311
  }
329
312
 
330
- // ---------------------------------------------------------------------------
331
- // solveModel helpers
332
- // ---------------------------------------------------------------------------
333
-
334
313
  /** `MaxIter` per mode; `maxiter` goes through C `atoi` (no digits -> 0). @see neatoinit.c:1280-1287 */
335
314
  export function neatoMaxIter(maxiter: string | undefined, mode: number, n: number): number {
336
315
  if (maxiter !== undefined) return parseInt(maxiter, 10) || 0;
@@ -350,11 +329,13 @@ interface MajorizationCtx {
350
329
  readonly haveLen: boolean;
351
330
  /** `opt_*` bits from `checkExp` and `checkStart`. */
352
331
  readonly opts: number;
332
+ /** The layout's resolved overlap mode (C's `am`). */
333
+ readonly am: AdjustData;
353
334
  }
354
335
 
355
336
  /**
356
337
  * The solver step of `majorization`: `stress_majorization_with_hierarchy` for
357
- * MODE_HIER, else the kD_mkernel (MODE_IPSEP without constraints runs it too).
338
+ * MODE_HIER, `stress_majorization_cola` for MODE_IPSEP, else the kD_mkernel.
358
339
  * Returns C's `rv`; the coordinates are left in `dCoords`.
359
340
  * @see lib/neatogen/neatoinit.c:majorization
360
341
  */
@@ -370,17 +351,22 @@ function solveStress(
370
351
  dim: DFLT_DIM, opts, model, maxi, epsilon, levelsGap: levelsGapOf(g),
371
352
  });
372
353
  }
373
- // C ipsep (stress_majorization_cola, constrained_majorization_ipsep.c:150) always uses
374
- // compute_apsp_packed; kD_mkernel uses the weighted APSP iff graph->ewgts (stress.c:855).
375
- const weighted = haveLen && mode !== MODE_IPSEP;
376
- const Dij = weighted ? computeWeightedApspPacked(vtx, n) : computeApspPacked(vtx, n);
354
+ if (mode === MODE_IPSEP) {
355
+ // mg is the root graph, g the component. @see neatoinit.c:1121-1170
356
+ const opt = ipsepOptions(g.root, g, nodeList, c.am);
357
+ return stressMajorizationCola(vtx, n, dCoords, nodeList, {
358
+ dim: DFLT_DIM, model, maxi, epsilon, opt,
359
+ });
360
+ }
361
+ // kD_mkernel uses the weighted APSP iff graph->ewgts (stress.c:855).
362
+ const Dij = haveLen ? computeWeightedApspPacked(vtx, n) : computeApspPacked(vtx, n);
377
363
  return stressMajorizationKDMkernel(Dij, n, dCoords, nodeList, {
378
- dim: DFLT_DIM, opts, maxi, epsilon, cola: mode === MODE_IPSEP,
364
+ dim: DFLT_DIM, opts, maxi, epsilon,
379
365
  });
380
366
  }
381
367
 
382
368
  /** Run stress majorization and write positions back. @see lib/neatogen/neatoinit.c:majorization */
383
- export function runMajorization(g: Graph, mode: number, model: number): void {
369
+ export function runMajorization(g: Graph, mode: number, model: number, am: AdjustData): void {
384
370
  const nodeList = assignNodeIds(g);
385
371
  setEdgeLen(g); // scan_graph_mode else-branch: ED_dist for major/hier/ipsep
386
372
  const n = nodeList.length;
@@ -391,7 +377,7 @@ export function runMajorization(g: Graph, mode: number, model: number): void {
391
377
  const haveDir = mode === MODE_HIER || mode === MODE_IPSEP;
392
378
  const vtx = makeGraphDataC(g, nodeList, haveLen, haveDir, mode);
393
379
  const dCoords = [new Float64Array(n), new Float64Array(n)];
394
- if (solveStress({ g, mode, model, haveLen, opts }, vtx, dCoords, nodeList) < 0) {
380
+ if (solveStress({ g, mode, model, haveLen, opts, am }, vtx, dCoords, nodeList) < 0) {
395
381
  agerr('prev', 'layout aborted');
396
382
  return;
397
383
  }
@@ -400,8 +386,13 @@ export function runMajorization(g: Graph, mode: number, model: number): void {
400
386
  }
401
387
  }
402
388
 
389
+ /** The overlap mode when the caller has none to pass (AM_NONE). @see lib/neatogen/adjust.h */
390
+ const NO_ADJUST: AdjustData = { mode: AM_NONE, print: 'none', value: 0 };
391
+
403
392
  /** Dispatch to the layout solver for the mode. @see lib/neatogen/neatoinit.c:neatoLayout */
404
- export function solveModel(g: Graph, mode: number, model: number): void {
393
+ export function solveModel(
394
+ g: Graph, mode: number, model: number, am: AdjustData = NO_ADJUST,
395
+ ): void {
405
396
  if (g.nodes.size < 2) return;
406
397
  assertSupported(g, mode, model);
407
398
  if (mode === MODE_KK) return kkNeato(g, g.nodes.size, model);
@@ -411,7 +402,7 @@ export function solveModel(g: Graph, mode: number, model: number): void {
411
402
  sgdLayout(g, model);
412
403
  return;
413
404
  }
414
- runMajorization(g, mode, model);
405
+ runMajorization(g, mode, model, am);
415
406
  }
416
407
 
417
408
  // ---------------------------------------------------------------------------
@@ -0,0 +1,158 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * The `ipsep_options` `majorization` builds for `stress_majorization_cola`
5
+ * (mode=ipsep), and the cluster membership it carries.
6
+ *
7
+ * Inputs reuse the port's existing parsers: the overlap mode is the
8
+ * `AdjustData` that `graphAdjustMode` / `getAdjustMode` (`fdp-adjust.ts`,
9
+ * C `adjust.c:graphAdjustMode`) resolved once per layout, passed in as C
10
+ * passes `am`, so an unrecognized `overlap` value does not warn twice; the gap
11
+ * comes from `sepFactor` (`sep-factor.ts`, C `adjust.c:sepFactor`); `levelsgap`
12
+ * goes through `lateDouble` (C `late_double`) and `diredgeconstraints` through
13
+ * `mapbool`. The `Verbose` lines of the C block are not ported (the port has
14
+ * no Verbose), nor the `DEBUG_COLA` dump.
15
+ *
16
+ * Node indices follow `nodes` (C `ND_id`, assigned in `agfstnode(g)` order),
17
+ * which is the order of the layout's coordinate arrays.
18
+ *
19
+ * @see lib/neatogen/neatoinit.c:majorization (1121-1170)
20
+ * @see lib/neatogen/neatoinit.c:cluster_map
21
+ * @see lib/neatogen/digcola.h:ipsep_options
22
+ */
23
+
24
+ import type { Box, Point } from '../../model/geom.js';
25
+ import type { Graph } from '../../model/graph.js';
26
+ import type { Node } from '../../model/node.js';
27
+ import { lateDouble } from '../../common/nodeinit.js';
28
+ import { mapbool, isACluster } from '../dot/rank.js';
29
+ import { nodesInSeq } from '../dot/decomp.js';
30
+ import { aggetGraph } from '../fdp/fdp-model.js';
31
+ import { AM_IPSEP, AM_VPSC, type AdjustData } from './fdp-adjust.js';
32
+ import { DFLT_MARGIN, sepFactor } from './sep-factor.js';
33
+ import type { ClusterData, IpsepOptions } from './quad-prog-vpsc.js';
34
+
35
+ /** `POINTS_PER_INCH`, the divisor of C's `PS2INCH` macro. @see lib/common/geom.h:PS2INCH */
36
+ const POINTS_PER_INCH = 72;
37
+ /** `strncasecmp(str, "hier", 4)`: the DiG-CoLa prefix of `diredgeconstraints`. */
38
+ const HIER_PREFIX = 'hier';
39
+
40
+ /** C `PS2INCH(a_points)`: `(a_points)/(double)POINTS_PER_INCH` (a divide, not `* 1/72`). */
41
+ const ps2inch = (points: number): number => points / POINTS_PER_INCH;
42
+
43
+ /** C `boxf` zero-initialised by `gv_calloc`. */
44
+ const zeroBox = (): Box => ({ ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } });
45
+
46
+ /**
47
+ * Indices (in `agfstnode(g)` order) of a cluster's members. A member that is
48
+ * not in `g` gets C's fall-through index `agnnodes(g)`.
49
+ * @see lib/neatogen/neatoinit.c:cluster_map (inner loops)
50
+ */
51
+ function memberIndices(subg: Graph, nodes: readonly Node[]): Int32Array {
52
+ const members = nodesInSeq(subg);
53
+ const c = new Int32Array(members.length);
54
+ members.forEach((n, k) => {
55
+ let ind = 0;
56
+ for (const gn of nodes) {
57
+ if (gn.id === n.id) break;
58
+ ind++;
59
+ }
60
+ c[k] = ind;
61
+ });
62
+ return c;
63
+ }
64
+
65
+ /** The top-level clusters of `mg`, in `agfstsubg` order. @see lib/common/utils.c:is_a_cluster */
66
+ function topClusters(mg: Graph): Graph[] {
67
+ return [...mg.subgraphs.values()].filter((s) => s !== mg.root && isACluster(s));
68
+ }
69
+
70
+ /**
71
+ * Cluster membership of `g`'s nodes: one index array per top-level cluster of
72
+ * the master graph, the nodes in no cluster (`toplevel`), and a zeroed
73
+ * bounding box per cluster.
74
+ * @see lib/neatogen/neatoinit.c:cluster_map
75
+ */
76
+ export function clusterMap(mg: Graph, g: Graph, nodes: readonly Node[]): ClusterData {
77
+ const nnodes = nodes.length;
78
+ // C bitarray_t of agnnodes(g) bits; an out-of-range set (a member not in g) is dropped.
79
+ const assigned = new Uint8Array(nnodes);
80
+ const clusters = topClusters(mg);
81
+ let ntoplevel = nnodes;
82
+ let nvars = 0;
83
+ const cs: Int32Array[] = [];
84
+ const cn = new Int32Array(clusters.length);
85
+ clusters.forEach((subg, i) => {
86
+ /* clusters are processed by separate calls to ordered_edges */
87
+ const c = memberIndices(subg, nodes);
88
+ cn[i] = c.length;
89
+ nvars += c.length;
90
+ cs.push(c);
91
+ for (const ind of c) {
92
+ assigned[ind] = 1;
93
+ ntoplevel--;
94
+ }
95
+ });
96
+ const toplevel = new Int32Array(ntoplevel);
97
+ let j = 0;
98
+ for (let i = 0; i < nnodes; i++) {
99
+ if (assigned[i] === 0) toplevel[j++] = i;
100
+ }
101
+ return {
102
+ nvars, nclusters: clusters.length, clustersizes: cn, clusters: cs,
103
+ ntoplevel, toplevel, bb: clusters.map(zeroBox),
104
+ };
105
+ }
106
+
107
+ /**
108
+ * `diredgeconstraints`: true-ish -> 1 (directed edge constraints), a `hier`
109
+ * prefix (any case) -> 2 (DiG-CoLa level constraints), else 0.
110
+ * @see lib/neatogen/neatoinit.c:majorization (1130-1140)
111
+ */
112
+ function diredgesOf(str: string | undefined): 0 | 1 | 2 {
113
+ if (mapbool(str)) return 1;
114
+ if (str !== undefined && str.slice(0, HIER_PREFIX.length).toLowerCase() === HIER_PREFIX) return 2;
115
+ return 0;
116
+ }
117
+
118
+ /**
119
+ * `overlap=ipsep` -> 1 (non-overlap constraints), `overlap=vpsc` -> 2 (remove
120
+ * overlaps after layout), else 0.
121
+ * @see lib/neatogen/neatoinit.c:majorization (1141-1150)
122
+ */
123
+ function noverlapOf(am: AdjustData): 0 | 1 | 2 {
124
+ if (am.mode === AM_IPSEP) return 1;
125
+ if (am.mode === AM_VPSC) return 2;
126
+ return 0;
127
+ }
128
+
129
+ /**
130
+ * The gap enforced when removing overlap: twice the additive `sep` margin
131
+ * (`opt.gap` is the gap size, not the margin), else twice `DFLT_MARGIN`.
132
+ * @see lib/neatogen/neatoinit.c:majorization (1151-1157)
133
+ */
134
+ function gapOf(g: Graph): Point {
135
+ const margin = sepFactor(g);
136
+ /* Multiply by 2 since opt.gap is the gap size, not the margin */
137
+ if (margin.doAdd) {
138
+ return { x: 2.0 * ps2inch(margin.x), y: 2.0 * ps2inch(margin.y) };
139
+ }
140
+ const gap = 2.0 * ps2inch(DFLT_MARGIN);
141
+ return { x: gap, y: gap };
142
+ }
143
+
144
+ /**
145
+ * The options `majorization` hands `stress_majorization_cola` for one
146
+ * component `g` of the master graph `mg`; `am` is the layout's resolved
147
+ * overlap mode.
148
+ * @see lib/neatogen/neatoinit.c:majorization (1121-1170)
149
+ */
150
+ export function ipsepOptions(mg: Graph, g: Graph, nodes: readonly Node[], am: AdjustData): IpsepOptions {
151
+ const clusters = clusterMap(mg, g, nodes);
152
+ const edgeGap = lateDouble(aggetGraph(g, 'levelsgap'), 0.0, -Number.MAX_VALUE);
153
+ const diredges = diredgesOf(aggetGraph(g, 'diredgeconstraints'));
154
+ const noverlap = noverlapOf(am);
155
+ const gap = gapOf(g);
156
+ const nsize = nodes.map((v) => ({ x: v.info.width, y: v.info.height }));
157
+ return { diredges, edgeGap, noverlap, gap, nsize, clusters };
158
+ }
@@ -0,0 +1,189 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * Linear equations (Ax = b) by LU decomposition with partial pivoting and row
5
+ * equilibration (Ken Turkowski). `luDecompose` factors the coefficient matrix;
6
+ * `luSolve` solves against one unit vector per call.
7
+ *
8
+ * Floating point follows the oracle's clang -O3 arm64 code (16.1.0
9
+ * `libgvplugin_neato_layout`): the elimination `lu[i][j] -= mult * lu[k][j]`
10
+ * is fused (fmla/fmsub), and `luSolve`'s dot products are vectorised 8 terms
11
+ * at a time as fmul + in-order fadd (unfused) with a fused (fmadd) scalar tail.
12
+ *
13
+ * @see lib/neatogen/lu.c
14
+ */
15
+
16
+ import { fma } from '../../common/fma.js';
17
+ import { fmaxf as fmax } from './quad-prog-solve.js';
18
+
19
+ /**
20
+ * State for an LU decomposition. `null` is a freed (or never allocated) field.
21
+ * @see lib/neatogen/neato.h:lu_t
22
+ */
23
+ export interface LuT {
24
+ /** Composite of the upper and lower triangular matrices. */
25
+ lu: Float64Array[] | null;
26
+ /** Pivot sequence. */
27
+ ps: Int32Array | null;
28
+ }
29
+
30
+ /** clang's vector width for `luSolve`'s dot products (4 x 2 doubles). */
31
+ const DOT_VECTOR_TERMS = 8;
32
+
33
+ /**
34
+ * An m x n array of rows over one buffer, every entry `ival`.
35
+ * Lives here (not in a stuff.c port) because lu.c is its first ported caller.
36
+ * @see lib/neatogen/stuff.c:new_array
37
+ */
38
+ export function newArray(m: number, n: number, ival: number): Float64Array[] {
39
+ const mem = new Float64Array(m * n);
40
+ const rv: Float64Array[] = [];
41
+ for (let i = 0; i < m; i++) {
42
+ rv.push(mem.subarray(i * n, (i + 1) * n));
43
+ rv[i]!.fill(ival);
44
+ }
45
+ return rv;
46
+ }
47
+
48
+ /**
49
+ * Copy `a` into `lu.lu`, record 1/largest per row in `scales` and the identity
50
+ * pivot sequence; false on a zero row (C returns 0 there).
51
+ * @see lib/neatogen/lu.c:lu_decompose (lu.c:74-86)
52
+ */
53
+ function luScaleRows(lu: LuT, a: readonly ArrayLike<number>[], n: number, scales: Float64Array): boolean {
54
+ const m = lu.lu!;
55
+ const ps = lu.ps!;
56
+ for (let i = 0; i < n; i++) { // for each row
57
+ /* Find the largest element in each row for row equilibration */
58
+ let biggest = 0;
59
+ for (let j = 0; j < n; j++) biggest = fmax(biggest, Math.abs((m[i]![j] = a[i]![j]!)));
60
+ if (biggest > 0.0) scales[i] = 1.0 / biggest;
61
+ else return false; /* Zero row: singular matrix */
62
+ ps[i] = i; // initialize pivot sequence
63
+ }
64
+ return true;
65
+ }
66
+
67
+ /**
68
+ * The scaled-largest row index at or below `k` in column `k`, or -1 when the
69
+ * column is zero. `pivotindex` carries over between columns, as in C.
70
+ * @see lib/neatogen/lu.c:lu_decompose (lu.c:88-102)
71
+ */
72
+ function luFindPivot(lu: LuT, k: number, n: number, scales: Float64Array, pivotindex: number): number {
73
+ const m = lu.lu!;
74
+ const ps = lu.ps!;
75
+ /* Find the largest element in each column to pivot around */
76
+ let biggest = 0;
77
+ for (let i = k; i < n; i++) {
78
+ const tempf = Math.abs(m[ps[i]!]![k]!) * scales[ps[i]!]!;
79
+ if (biggest < tempf) {
80
+ biggest = tempf;
81
+ pivotindex = i;
82
+ }
83
+ }
84
+ if (biggest <= 0.0) return -1; /* Zero column: singular matrix */
85
+ return pivotindex;
86
+ }
87
+
88
+ /**
89
+ * Pivot on column `k`, eliminating an extra variable (fused multiply-subtract).
90
+ * @see lib/neatogen/lu.c:lu_decompose (lu.c:107-113)
91
+ */
92
+ function luEliminate(lu: LuT, k: number, n: number): void {
93
+ const m = lu.lu!;
94
+ const ps = lu.ps!;
95
+ const rowK = m[ps[k]!]!;
96
+ const pivot = rowK[k]!;
97
+ for (let i = k + 1; i < n; i++) {
98
+ const rowI = m[ps[i]!]!;
99
+ const mult = (rowI[k] = rowI[k]! / pivot);
100
+ for (let j = k + 1; j < n; j++) rowI[j] = fma(-mult, rowK[j]!, rowI[j]!);
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Decompose the n x n matrix `a` into `lu`. 1 on success; 0 (with `lu` freed)
106
+ * when `a` is singular. n = 0 reads `ps[-1]` in C (undefined behaviour); no
107
+ * caller reaches it (stress_majorization_cola returns early for one node).
108
+ * @see lib/neatogen/lu.c:lu_decompose
109
+ */
110
+ export function luDecompose(lu: LuT, a: readonly ArrayLike<number>[], n: number): 0 | 1 {
111
+ lu.lu = newArray(n, n, 0.0);
112
+ lu.ps = new Int32Array(n);
113
+ const scales = new Float64Array(n);
114
+
115
+ if (!luScaleRows(lu, a, n, scales)) {
116
+ luFree(lu);
117
+ return 0; /* Zero row: singular matrix */
118
+ }
119
+
120
+ for (let k = 0, pivotindex = 0; k < n - 1; k++) { // for each column
121
+ pivotindex = luFindPivot(lu, k, n, scales, pivotindex);
122
+ if (pivotindex < 0) {
123
+ luFree(lu);
124
+ return 0; /* Zero column: singular matrix */
125
+ }
126
+ if (pivotindex !== k) { /* Update pivot sequence */
127
+ const ps = lu.ps;
128
+ const t = ps[k]!;
129
+ ps[k] = ps[pivotindex]!;
130
+ ps[pivotindex] = t;
131
+ }
132
+ /* Pivot, eliminating an extra variable each time */
133
+ luEliminate(lu, k, n);
134
+ }
135
+
136
+ if (lu.lu[lu.ps[n - 1]!]![n - 1] === 0.0) {
137
+ luFree(lu);
138
+ return 0; /* Singular matrix */
139
+ }
140
+ return 1;
141
+ }
142
+
143
+ /**
144
+ * `sum row[j] * x[j]` for j in [from, to), as clang emits it: the first
145
+ * 8-multiple of terms as fmul + in-order fadd, the rest fused.
146
+ * @see lib/neatogen/lu.c:lu_solve (lu.c:140-141, 147-148)
147
+ */
148
+ function luDot(row: Float64Array, x: Float64Array, from: number, to: number): number {
149
+ const vecEnd = from + (to - from) - ((to - from) % DOT_VECTOR_TERMS);
150
+ let dot = 0;
151
+ let j = from;
152
+ for (; j < vecEnd; j++) dot += row[j]! * x[j]!;
153
+ for (; j < to; j++) dot = fma(row[j]!, x[j]!, dot);
154
+ return dot;
155
+ }
156
+
157
+ /**
158
+ * Solve A x = e_bi with the decomposition from `luDecompose`.
159
+ * @see lib/neatogen/lu.c:lu_solve
160
+ */
161
+ export function luSolve(lu: LuT, x: Float64Array, bi: number, n: number): void {
162
+ const m = lu.lu!;
163
+ const ps = lu.ps!;
164
+ /* Vector reduction using U triangular matrix */
165
+ for (let i = 0; i < n; i++) {
166
+ const dot = luDot(m[ps[i]!]!, x, 0, i);
167
+ x[i] = (ps[i] === bi ? 1 : 0) - dot;
168
+ }
169
+
170
+ /* Back substitution, in L triangular matrix */
171
+ for (let i = n - 1; i >= 0; i--) {
172
+ const row = m[ps[i]!]!;
173
+ const dot = luDot(row, x, i + 1, n);
174
+ x[i] = (x[i]! - dot) / row[i]!;
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Release the decomposition. C frees without clearing the pointers; the port
180
+ * drops them to `null`.
181
+ * @see lib/neatogen/lu.c:lu_free
182
+ */
183
+ export function luFree(lu: LuT | null): void {
184
+ if (lu === null) {
185
+ return;
186
+ }
187
+ lu.lu = null;
188
+ lu.ps = null;
189
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * Matrix inversion by LU decomposition (Ken Turkowski).
5
+ * @see lib/neatogen/matinv.c
6
+ */
7
+
8
+ import { luDecompose, luSolve, luFree, type LuT } from './lu.js';
9
+
10
+ /**
11
+ * Invert the leading n x n block of `A` into `Ainv`: solve for one row of
12
+ * `Ainv` per unit vector, then transpose. 1 on success, 0 when singular
13
+ * (`Ainv` untouched).
14
+ * @see lib/neatogen/matinv.c:matinv
15
+ */
16
+ export function matinv(A: readonly ArrayLike<number>[], Ainv: Float64Array[], n: number): 0 | 1 {
17
+ /* Decompose matrix into L and U triangular matrices */
18
+ const lu: LuT = { lu: null, ps: null };
19
+ if (luDecompose(lu, A, n) === 0) return 0; // singular
20
+
21
+ /* Invert matrix by solving n simultaneous equations n times */
22
+ for (let i = 0; i < n; i++) {
23
+ luSolve(lu, Ainv[i]!, i, n); // into a row of Ainv: fix later
24
+ }
25
+ luFree(lu);
26
+
27
+ /* Transpose matrix */
28
+ for (let i = 0; i < n; i++) {
29
+ for (let j = 0; j < i; j++) {
30
+ const t = Ainv[i]![j]!;
31
+ Ainv[i]![j] = Ainv[j]![i]!;
32
+ Ainv[j]![i] = t;
33
+ }
34
+ }
35
+
36
+ return 1;
37
+ }