@knowvah/dot-engine 2.12.2 → 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 (190) hide show
  1. package/dist/common/compass-port.d.ts.map +1 -1
  2. package/dist/common/graph-init.d.ts.map +1 -1
  3. package/dist/common/htmltable-label.d.ts.map +1 -1
  4. package/dist/common/htmltable-lex.d.ts +3 -1
  5. package/dist/common/htmltable-lex.d.ts.map +1 -1
  6. package/dist/common/htmltable-parse-image.d.ts +23 -0
  7. package/dist/common/htmltable-parse-image.d.ts.map +1 -0
  8. package/dist/common/htmltable-parse-state.d.ts +4 -0
  9. package/dist/common/htmltable-parse-state.d.ts.map +1 -1
  10. package/dist/common/htmltable-parse.d.ts +33 -2
  11. package/dist/common/htmltable-parse.d.ts.map +1 -1
  12. package/dist/common/poly-inside.d.ts.map +1 -1
  13. package/dist/common/splines-geom.d.ts +2 -1
  14. package/dist/common/splines-geom.d.ts.map +1 -1
  15. package/dist/common/splines-routespl.d.ts +3 -0
  16. package/dist/common/splines-routespl.d.ts.map +1 -1
  17. package/dist/index.js +21301 -21229
  18. package/dist/index.js.map +4 -4
  19. package/dist/layout/dot/classify.d.ts.map +1 -1
  20. package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
  21. package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
  22. package/dist/layout/dot/edge-route-chain.d.ts +20 -16
  23. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  24. package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
  25. package/dist/layout/dot/flat.d.ts +22 -7
  26. package/dist/layout/dot/flat.d.ts.map +1 -1
  27. package/dist/layout/dot/mincross-flat.d.ts +10 -1
  28. package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
  29. package/dist/layout/dot/mincross.d.ts +6 -1
  30. package/dist/layout/dot/mincross.d.ts.map +1 -1
  31. package/dist/layout/dot/ns-subtree.d.ts +9 -6
  32. package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
  33. package/dist/layout/dot/pack-components.d.ts +4 -3
  34. package/dist/layout/dot/pack-components.d.ts.map +1 -1
  35. package/dist/layout/dot/position-aux.d.ts +62 -20
  36. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  37. package/dist/layout/dot/position-bbox.d.ts.map +1 -1
  38. package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
  39. package/dist/layout/dot/position.d.ts.map +1 -1
  40. package/dist/layout/dot/rank-dot2.d.ts +7 -25
  41. package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
  42. package/dist/layout/dot/self-loop.d.ts +11 -4
  43. package/dist/layout/dot/self-loop.d.ts.map +1 -1
  44. package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
  45. package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
  46. package/dist/layout/dot/splines-route.d.ts +6 -3
  47. package/dist/layout/dot/splines-route.d.ts.map +1 -1
  48. package/dist/layout/dot/straight-edges.d.ts.map +1 -1
  49. package/dist/layout/fdp/tlayout.d.ts +3 -0
  50. package/dist/layout/fdp/tlayout.d.ts.map +1 -1
  51. package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
  52. package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
  53. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
  54. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
  55. package/dist/layout/neato/conjgrad.d.ts +7 -6
  56. package/dist/layout/neato/conjgrad.d.ts.map +1 -1
  57. package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
  58. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
  59. package/dist/layout/neato/matrix-ops.d.ts +0 -6
  60. package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
  61. package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
  62. package/dist/model/rankEntry.d.ts +3 -1
  63. package/dist/model/rankEntry.d.ts.map +1 -1
  64. package/dist/ortho/index.d.ts +0 -1
  65. package/dist/ortho/index.d.ts.map +1 -1
  66. package/dist/ortho/partition.d.ts +2 -4
  67. package/dist/ortho/partition.d.ts.map +1 -1
  68. package/dist/pathplan/route.d.ts +93 -0
  69. package/dist/pathplan/route.d.ts.map +1 -1
  70. package/dist/render/dot/agwrite.d.ts +21 -9
  71. package/dist/render/dot/agwrite.d.ts.map +1 -1
  72. package/dist/render/dot/types.d.ts +7 -2
  73. package/dist/render/dot/types.d.ts.map +1 -1
  74. package/dist/render.js +21301 -21229
  75. package/dist/render.js.map +4 -4
  76. package/dist/util/overflow.d.ts +37 -0
  77. package/dist/util/overflow.d.ts.map +1 -0
  78. package/package.json +3 -2
  79. package/src/common/compass-port.ts +36 -20
  80. package/src/common/graph-init.ts +11 -1
  81. package/src/common/htmltable-label.ts +9 -4
  82. package/src/common/htmltable-lex.ts +5 -2
  83. package/src/common/htmltable-parse-image.ts +69 -0
  84. package/src/common/htmltable-parse-state.ts +6 -0
  85. package/src/common/htmltable-parse.ts +34 -44
  86. package/src/common/poly-inside.ts +11 -5
  87. package/src/common/splines-geom.ts +24 -6
  88. package/src/common/splines-routespl.ts +32 -0
  89. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
  90. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
  91. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
  92. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
  93. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
  94. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
  95. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
  96. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
  97. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
  98. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
  99. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
  100. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
  101. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
  102. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
  103. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
  104. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
  105. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
  106. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
  107. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
  108. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
  109. package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
  110. package/src/layout/dot/classify.ts +5 -2
  111. package/src/layout/dot/edge-route-chain-views.ts +120 -0
  112. package/src/layout/dot/edge-route-chain.ts +103 -117
  113. package/src/layout/dot/edge-route-faithful.ts +20 -5
  114. package/src/layout/dot/flat.ts +38 -17
  115. package/src/layout/dot/mincross-flat.ts +15 -5
  116. package/src/layout/dot/mincross.ts +6 -2
  117. package/src/layout/dot/ns-subtree.ts +11 -7
  118. package/src/layout/dot/pack-components.ts +6 -4
  119. package/src/layout/dot/position-aux.ts +112 -39
  120. package/src/layout/dot/position-bbox.ts +14 -1
  121. package/src/layout/dot/position-ycoords.ts +7 -1
  122. package/src/layout/dot/position.ts +4 -1
  123. package/src/layout/dot/rank-dot2.ts +13 -94
  124. package/src/layout/dot/self-loop.ts +29 -11
  125. package/src/layout/dot/splines-flat-multi.ts +12 -4
  126. package/src/layout/dot/splines-route.ts +10 -11
  127. package/src/layout/dot/straight-edges.ts +5 -3
  128. package/src/layout/fdp/tlayout.ts +6 -5
  129. package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
  130. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
  131. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
  132. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
  133. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
  134. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
  135. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
  136. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
  137. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
  138. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
  139. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
  140. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
  141. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
  142. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
  143. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
  144. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
  145. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
  146. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
  147. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
  148. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
  149. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
  150. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
  151. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
  152. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
  153. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
  154. package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
  155. package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
  156. package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
  157. package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
  158. package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
  159. package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
  160. package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
  161. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
  162. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
  163. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
  164. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
  165. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
  166. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
  167. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
  168. package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
  169. package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
  170. package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
  171. package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
  172. package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
  173. package/src/layout/neato/conjgrad.ts +38 -35
  174. package/src/layout/neato/matrix-ops-dense.ts +2 -20
  175. package/src/layout/neato/matrix-ops.ts +0 -20
  176. package/src/layout/neato/quad-prog-vpsc.ts +7 -5
  177. package/src/layout/neato/smart-ini-x.ts +15 -15
  178. package/src/layout/neato/stress-subspace.ts +5 -5
  179. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
  180. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
  181. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
  182. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
  183. package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
  184. package/src/model/rankEntry.ts +3 -1
  185. package/src/ortho/index.ts +0 -1
  186. package/src/ortho/partition.ts +10 -22
  187. package/src/pathplan/route.ts +14 -4
  188. package/src/render/dot/agwrite.ts +35 -15
  189. package/src/render/dot/types.ts +7 -2
  190. package/src/util/overflow.ts +74 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Overflow-checked arithmetic helpers.
3
+ *
4
+ * @see lib/util/overflow.h
5
+ */
6
+ /**
7
+ * Add two integers, clamping to lower and upper type bounds.
8
+ *
9
+ * Returns the sum `a + b`, or `INT_MAX`/`INT_MIN` on overflow/underflow. C's
10
+ * operands are `int`; the port applies the same three branches to its numbers
11
+ * as they are, with no int32 wrap of the inputs.
12
+ * @see lib/util/overflow.h:sadd_saturate
13
+ */
14
+ export declare function saddSaturate(a: number, b: number): number;
15
+ /**
16
+ * Divide two double floating-point values, checking for overflow.
17
+ *
18
+ * Returns the quotient `n / d`, or `null` where C returns `true` and leaves
19
+ * `*res` as it was: the quotient is not finite (a zero or subnormal divisor,
20
+ * a non-finite operand, or a result past `DBL_MAX`). A call site writes C's
21
+ * "assign the fallback, then overwrite on success" as `fdivOverflow(n, d) ??
22
+ * fallback`; a zero quotient is a result, and `??` keeps it.
23
+ * @see lib/util/overflow.h:fdiv_overflow
24
+ */
25
+ export declare function fdivOverflow(n: number, d: number): number | null;
26
+ /**
27
+ * Divide two floating-point values, checking for overflow.
28
+ *
29
+ * The `float` twin of {@link fdivOverflow}. C's parameters and quotient are
30
+ * `float`, so the operands and the quotient are rounded to float32: a
31
+ * quotient past `FLT_MAX` is an overflow here though it is finite as a
32
+ * double. Dividing two float32 values in double and rounding once gives
33
+ * IEEE single division's result (53 >= 2 * 24 + 2 bits).
34
+ * @see lib/util/overflow.h:fdivf_overflow
35
+ */
36
+ export declare function fdivfOverflow(n: number, d: number): number | null;
37
+ //# sourceMappingURL=overflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overflow.d.ts","sourceRoot":"","sources":["../../src/util/overflow.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAMH;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAYzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAShE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASjE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowvah/dot-engine",
3
- "version": "2.12.2",
3
+ "version": "2.12.3",
4
4
  "description": "Faithful TypeScript port of Graphviz (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork) — no C: no native binary, no WASM. Oracle-verified against the C implementation, runs in the browser.",
5
5
  "keywords": [
6
6
  "graphviz",
@@ -65,9 +65,10 @@
65
65
  "typecheck": "tsc --noEmit --stableTypeOrdering",
66
66
  "pretypecheck:ts7": "npm run parser:regen",
67
67
  "typecheck:ts7": "tsgo --noEmit",
68
+ "codeql:gate": "bash test/tools/codeql-gate.sh",
68
69
  "parser:regen": "peggy --format es --dts src/parser/dot.pegjs -o src/parser/dot.js",
69
70
  "survey:setup": "sh test/corpus/gen-headless-gvbindir.sh",
70
- "survey": "npm run survey:setup && GVBINDIR=${GVBINDIR:-/tmp/ghl} PARITY_OUT=parity-rules.json tsx test/corpus/survey.ts",
71
+ "survey": "npm run survey:setup && PARITY_OUT=parity-rules.json tsx test/corpus/survey.ts",
71
72
  "survey:fast": "SURVEY_MAX_PORT_MS=${SURVEY_MAX_PORT_MS:-60000} npm run survey",
72
73
  "survey:gate": "tsx test/corpus/rules-gate.ts",
73
74
  "survey:dashboard": "tsx test/corpus/dashboard.ts",
@@ -111,27 +111,40 @@ function invflipSide(side: number, rankdir: number): number {
111
111
 
112
112
  // ---------------------------------------------------------------------------
113
113
  // invflipAngle helpers
114
- // @see lib/common/shapes.c:invflip_angle (line 2606)
114
+ // @see lib/common/shapes.c:invflip_angle (line 2607)
115
115
  // ---------------------------------------------------------------------------
116
116
 
117
+ /** The RANKDIR_RL arm of invflip_angle, on ¼×π units; no match leaves the angle unchanged. */
117
118
  function invflipAngleRL(angle: number): number {
118
- if (angle === Math.PI) return -0.5 * Math.PI;
119
- if (angle === Math.PI * 0.75) return -0.25 * Math.PI;
120
- if (angle === Math.PI * 0.5) return 0;
121
- if (angle === 0) return Math.PI * 0.5;
122
- if (angle === Math.PI * -0.25) return Math.PI * 0.75;
123
- if (angle === Math.PI * -0.5) return Math.PI;
119
+ if (angle === 4) return -2;
120
+ if (angle === 3) return -1;
121
+ if (angle === 2) return 0;
122
+ if (angle === 0) return 2;
123
+ if (angle === -1) return 3;
124
+ if (angle === -2) return 4;
124
125
  return angle;
125
126
  }
126
127
 
127
- /** Adjust theta for rankdir. @see lib/common/shapes.c:invflip_angle (line 2606) */
128
+ /**
129
+ * Adjust theta for rankdir.
130
+ * @param angle Angle in units of ¼×π (C's `int`)
131
+ * @returns Computed angle in radians
132
+ * @see lib/common/shapes.c:invflip_angle (line 2607)
133
+ */
128
134
  function invflipAngle(angle: number, rankdir: number): number {
135
+ let a = angle;
129
136
  switch (rankdir) {
130
- case RANKDIR_BT: return -angle;
131
- case RANKDIR_LR: return angle - Math.PI * 0.5;
132
- case RANKDIR_RL: return invflipAngleRL(angle);
133
- default: return angle; // RANKDIR_TB: identity
137
+ case RANKDIR_BT:
138
+ // C: `angle *= -1` on an int, where 0 stays 0. In JS `-a` and `a * -1`
139
+ // turn 0 into -0, which would survive the conversion below; `0 - a`
140
+ // keeps it +0.
141
+ a = 0 - a;
142
+ break;
143
+ case RANKDIR_LR: a -= 2; break;
144
+ case RANKDIR_RL: a = invflipAngleRL(a); break;
145
+ default: break; // RANKDIR_TB: identity
134
146
  }
147
+ return a * 0.25 * Math.PI;
135
148
  }
136
149
 
137
150
  // ---------------------------------------------------------------------------
@@ -165,7 +178,10 @@ function compassBbox(n: Node, bp: Box | null): BboxResult {
165
178
  // ---------------------------------------------------------------------------
166
179
 
167
180
  type DirectionResult = {
168
- p: Point; theta: number; side: number;
181
+ p: Point;
182
+ /** C's `int theta`, in units of ¼×π; invflipAngle converts it to radians. */
183
+ theta: number;
184
+ side: number;
169
185
  constrain: boolean; clip: boolean; dyna: boolean;
170
186
  defined: boolean; rv: number;
171
187
  };
@@ -188,9 +204,9 @@ function dirUnrecognized(p: Point): DirectionResult {
188
204
  function dirN(rest: string, b: Box, ctr: Point, sides: number): DirectionResult {
189
205
  const base = { constrain: true, clip: false, dyna: false };
190
206
  switch (rest) {
191
- case '': return { ...base, p: { x: ctr.x, y: b.ur.y }, theta: Math.PI * 0.5, side: sides & TOP, defined: true, rv: 0 };
192
- case 'e': return { ...base, p: { x: b.ur.x, y: b.ur.y }, theta: Math.PI * 0.25, side: sides & (TOP | RIGHT), defined: true, rv: 0 };
193
- case 'w': return { ...base, p: { x: b.ll.x, y: b.ur.y }, theta: Math.PI * 0.75, side: sides & (TOP | LEFT), defined: true, rv: 0 };
207
+ case '': return { ...base, p: { x: ctr.x, y: b.ur.y }, theta: 2, side: sides & TOP, defined: true, rv: 0 };
208
+ case 'e': return { ...base, p: { x: b.ur.x, y: b.ur.y }, theta: 1, side: sides & (TOP | RIGHT), defined: true, rv: 0 };
209
+ case 'w': return { ...base, p: { x: b.ll.x, y: b.ur.y }, theta: 3, side: sides & (TOP | LEFT), defined: true, rv: 0 };
194
210
  default: return dirUnrecognized({ x: ctr.x, y: ctr.y });
195
211
  }
196
212
  }
@@ -198,9 +214,9 @@ function dirN(rest: string, b: Box, ctr: Point, sides: number): DirectionResult
198
214
  function dirS(rest: string, b: Box, ctr: Point, sides: number): DirectionResult {
199
215
  const base = { constrain: true, clip: false, dyna: false };
200
216
  switch (rest) {
201
- case '': return { ...base, p: { x: ctr.x, y: b.ll.y }, theta: -Math.PI * 0.5, side: sides & BOTTOM, defined: true, rv: 0 };
202
- case 'e': return { ...base, p: { x: b.ur.x, y: b.ll.y }, theta: -Math.PI * 0.25, side: sides & (BOTTOM | RIGHT), defined: true, rv: 0 };
203
- case 'w': return { ...base, p: { x: b.ll.x, y: b.ll.y }, theta: -Math.PI * 0.75, side: sides & (BOTTOM | LEFT), defined: true, rv: 0 };
217
+ case '': return { ...base, p: { x: ctr.x, y: b.ll.y }, theta: -2, side: sides & BOTTOM, defined: true, rv: 0 };
218
+ case 'e': return { ...base, p: { x: b.ur.x, y: b.ll.y }, theta: -1, side: sides & (BOTTOM | RIGHT), defined: true, rv: 0 };
219
+ case 'w': return { ...base, p: { x: b.ll.x, y: b.ll.y }, theta: -3, side: sides & (BOTTOM | LEFT), defined: true, rv: 0 };
204
220
  default: return dirUnrecognized({ x: ctr.x, y: ctr.y });
205
221
  }
206
222
  }
@@ -212,7 +228,7 @@ function dirE(rest: string, b: Box, ctr: Point, sides: number): DirectionResult
212
228
 
213
229
  function dirW(rest: string, b: Box, ctr: Point, sides: number): DirectionResult {
214
230
  if (rest.length > 0) return dirUnrecognized(ctr);
215
- return { p: { x: b.ll.x, y: ctr.y }, theta: Math.PI, side: sides & LEFT, constrain: true, clip: false, dyna: false, defined: true, rv: 0 };
231
+ return { p: { x: b.ll.x, y: ctr.y }, theta: 4, side: sides & LEFT, constrain: true, clip: false, dyna: false, defined: true, rv: 0 };
216
232
  }
217
233
 
218
234
  // ---------------------------------------------------------------------------
@@ -29,6 +29,7 @@ import type { RatioKind } from '../model/layoutParams.js';
29
29
  import { doGraphLabel } from '../layout/dot/graph-label.js';
30
30
  import { mapbool, setClType, LOCAL, GLOBAL, NOCLUST } from '../layout/dot/rank.js';
31
31
  import { cround } from './arith.js';
32
+ import { d2i } from '../util/math.js';
32
33
  import { agwarningf } from './agerr.js';
33
34
  import { setImageHooks, setImagePath } from './safefile.js';
34
35
 
@@ -119,10 +120,19 @@ function maptoken(p: string | undefined, names: string[], vals: number[]): numbe
119
120
  * `nodesep` is a plain late_double; `ranksep` additionally honours the
120
121
  * `equally` keyword (→ exact_ranksep) and a bare number that may be followed
121
122
  * by text. Absent attrs yield POINTS(DEFAULT_*) = 18 / 36.
123
+ *
124
+ * GD_nodesep is an `int` (types.h), and POINTS is `(int)(f + .5)`: past
125
+ * INT_MAX that conversion is undefined in C, and the oracle's arm64 build
126
+ * saturates it (scalar fcvtzs). `d2i` is that saturation. Evidence: corpus
127
+ * 2758 (`nodesep=40000000`, 2.88e9 pt) makes native 16.1.1 report an aux
128
+ * edge of `2147483701.000000`, INT_MAX plus two 27-pt half widths (issue
129
+ * #162). Only nodesep is saturated here: the other POINTS sites (ranksep,
130
+ * size, page) have no such evidence.
122
131
  * @see lib/common/input.c:665-681
123
132
  */
124
133
  function parseSepAttrs(g: Graph): void {
125
- g.info.nodesep = points(lateDouble(g.attrs.get('nodesep'), DEFAULT_NODESEP, MIN_NODESEP));
134
+ // `points` already rounded, so d2i's truncation changes nothing below INT_MAX.
135
+ g.info.nodesep = d2i(points(lateDouble(g.attrs.get('nodesep'), DEFAULT_NODESEP, MIN_NODESEP)));
126
136
  const p = g.attrs.get('ranksep');
127
137
  let xf = DEFAULT_RANKSEP;
128
138
  if (p !== undefined && p !== '') {
@@ -19,7 +19,7 @@ import { HtmlLexError } from './htmltable-lex.js';
19
19
  import { labelStderr, type StderrLines } from './htmltable-attr-warn.js';
20
20
  import { posHtmlLabel, type HtmlFontInfo, type PlacedHtml } from './htmltable-pos.js';
21
21
 
22
- /** parseHTML's rv for a label that failed to parse (`ctx->error`). */
22
+ /** parseHTML's rv once htmlerror or the lexer printed an error (`ctx->error`), with or without a label. */
23
23
  const HTML_PARSE_FATAL = 3;
24
24
 
25
25
  /** A built HTML label plus make_html_label's "problem" return value. */
@@ -48,9 +48,14 @@ export function makeHtmlLabelTo(
48
48
  stderr: StderrLines,
49
49
  ): HtmlLabelResult {
50
50
  const { fontname, fontsize, fontcolor, imageSizer, imageResolver, imageDpi, pencolor } = finfo;
51
- let lbl: HtmlLabel, lexWarn: boolean; // lexWarn: htmllex.c's ctx->warn, rv bit 1
51
+ let lbl: HtmlLabel, lexRv: number; // lexRv: clearHTMLlexer's `ctx->error ? 3 : ctx->warn`
52
52
  try {
53
- ({ label: lbl, warn: lexWarn } = parseHtmlLabelRv(content, stderr));
53
+ const parsed = parseHtmlLabelRv(content, stderr);
54
+ lbl = parsed.label;
55
+ // An error a rule reported without YYABORT (the image rule's) leaves the
56
+ // label: it is sized and drawn, and rv 3 makes make_label name the object.
57
+ // @see lib/common/htmllex.c:clearHTMLlexer
58
+ lexRv = parsed.error ? HTML_PARSE_FATAL : Number(parsed.warn);
54
59
  } catch (e) {
55
60
  // C aborts the HTML parse on a syntax error (YYABORT): parseHTML returns
56
61
  // rv 3 (ctx->error) with no label, and make_html_label returns it with
@@ -63,7 +68,7 @@ export function makeHtmlLabelTo(
63
68
  // which then flows table->cell->nested-table.
64
69
  // @see lib/common/htmltable.c:1911 (getPenColor), :1406/:1556 (inheritance)
65
70
  if (lbl.kind === 'table') inheritTablePenColor(lbl.table, pencolor);
66
- const rv = Number(lexWarn) | sizeHtmlLabel(lbl, measurer, {
71
+ const rv = lexRv | sizeHtmlLabel(lbl, measurer, {
67
72
  fontsize, fontname, imageSizer, imageResolver, imageDpi, stderr,
68
73
  });
69
74
  const placed = posHtmlLabel(lbl, { fontname, fontsize, fontcolor }, measurer);
@@ -161,11 +161,14 @@ const SYNTAX_ERROR = 'syntax error';
161
161
  */
162
162
  export class HtmlLexError extends HtmlParseError {
163
163
  readonly diagnostics: readonly string[];
164
+ /** Printed by `lexerror`, which unlike htmlerror and the expat path prints even when `ctx->error` is set. */
165
+ readonly unguarded: boolean;
164
166
 
165
- constructor(tag: string, message: string, diagnostics: readonly string[]) {
167
+ constructor(tag: string, message: string, diagnostics: readonly string[], unguarded = false) {
166
168
  super(tag);
167
169
  this.message = message;
168
170
  this.diagnostics = diagnostics;
171
+ this.unguarded = unguarded;
169
172
  }
170
173
  }
171
174
 
@@ -260,7 +263,7 @@ function checkTagToken(site: TokenSite): void {
260
263
  }
261
264
  if (KNOWN_TAGS.has(tag.name.toUpperCase())) return;
262
265
  const text = `Unknown HTML element <${tag.name}> on line ${lineAt(src, tok.start)} `;
263
- throw new HtmlLexError(tag.name.toUpperCase(), text, [`Error: ${text}`]);
266
+ throw new HtmlLexError(tag.name.toUpperCase(), text, [`Error: ${text}`], true);
264
267
  }
265
268
 
266
269
  /** The tokens one expat event gives the parser, after the errors C would hit. */
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+ /**
3
+ * The `image` rule of an HTML-like label's cell. Strings may stand before and
4
+ * after `<IMG>`: blank ones are ignored, and one with a non-space character is
5
+ * reported through `htmlerror` without `YYABORT`, so the parse goes on and the
6
+ * label keeps its image (parseHTML's rv is 3 with a label).
7
+ *
8
+ * @see lib/common/htmlparse.y:338-356
9
+ * @see lib/common/htmllex.c:52-59
10
+ */
11
+
12
+ import type { HtmlCellContent, HtmlImage, OpenToken, Token } from './htmltable-types.js';
13
+ import type { ParseState } from './htmltable-parse-state.js';
14
+ import { consume, consumedTag, emitWarnings, peek } from './htmltable-parse-state.js';
15
+ import { htmlErrorAtToken } from './htmltable-lex.js';
16
+ import type { CellScan } from './htmltable-parse.js';
17
+ import { MSG_SYNTAX_ERROR, consumeClose, parseError, skipStrings } from './htmltable-parse.js';
18
+
19
+ /** @see lib/common/htmlparse.y:340 (image rule, mid-rule action) */
20
+ const MSG_TEXT_BEFORE_IMG = 'Syntax error: non-space string used before <IMG>';
21
+ /** @see lib/common/htmlparse.y:343 (image rule, final action) */
22
+ const MSG_TEXT_AFTER_IMG = 'Syntax error: non-space string used after <IMG>';
23
+
24
+ /**
25
+ * `htmlerror` called from a rule action that does not abort: with `tok` the
26
+ * lookahead the lexer last returned, print the message and its context unless
27
+ * an error was printed before, and set `ctx->error`. The lexer ran for `tok`
28
+ * first, so that token's warnings come out ahead of the message. Without a
29
+ * lookahead the lexer failed fetching it and set `ctx->error` itself, so its
30
+ * own error is the one reported.
31
+ * @see lib/common/htmllex.c:htmlerror
32
+ */
33
+ const softError = (s: ParseState, tok: Token | undefined, message: string): void => {
34
+ if (tok === undefined) throw parseError(s, tok, message);
35
+ emitWarnings(s, tok);
36
+ if (s.error === true) return;
37
+ s.error = true;
38
+ for (const line of htmlErrorAtToken(message, tok)?.diagnostics ?? []) s.stderr?.write(`${line}\n`);
39
+ };
40
+
41
+ /** `T_img T_end_img` or `T_IMG`: the element itself. */
42
+ const parseImgContent = (s: ParseState, t: OpenToken): HtmlImage => {
43
+ consume(s);
44
+ const img: HtmlImage = {
45
+ kind: 'image',
46
+ src: t.attrs['src'] ?? '',
47
+ scale: t.attrs['scale'],
48
+ };
49
+ consumeClose(s, 'IMG');
50
+ return img;
51
+ };
52
+
53
+ /**
54
+ * `image : opt_space T_IMG opt_space` as the cell's only child, entered at the
55
+ * IMG token. The leading `opt_space` is strings alone, so an IMG that follows
56
+ * a tag is a syntax error. Its nonSpace check runs with the IMG as lookahead.
57
+ * The trailing `opt_space` reduces at whatever token follows the strings, and
58
+ * the rule's final action runs there by default reduction: its check is
59
+ * reported at that token even when the token then fails the cell rule.
60
+ * @see lib/common/htmlparse.y:338-356
61
+ */
62
+ export const scanCellImage = (s: ParseState, t: OpenToken, st: CellScan): HtmlCellContent[] => {
63
+ if (consumedTag(s, st.start)) throw parseError(s, t, MSG_SYNTAX_ERROR);
64
+ if (st.textNonSpace) softError(s, t, MSG_TEXT_BEFORE_IMG);
65
+ st.kind = 'image';
66
+ const img = parseImgContent(s, t);
67
+ if (skipStrings(s)) softError(s, peek(s), MSG_TEXT_AFTER_IMG);
68
+ return [img];
69
+ };
@@ -25,10 +25,16 @@ export interface ParseState {
25
25
  warn?: boolean;
26
26
  /** What the lexer wrote after its last token, printed when the parser asks for more. */
27
27
  eof?: LexerOutput;
28
+ /** `ctx->error`: htmlerror printed from a rule that went on parsing; the label's rv is 3. */
29
+ error?: boolean;
28
30
  }
29
31
 
30
32
  export const peek = (s: ParseState): Token | undefined => s.tokens[s.pos];
31
33
 
34
+ /** True when a tag, not only strings, was consumed since `start` (an `opt_space` is strings alone). */
35
+ export const consumedTag = (s: ParseState, start: number): boolean =>
36
+ s.tokens.slice(start, s.pos).some((t) => t.type !== 'text');
37
+
32
38
  /**
33
39
  * Print what the C lexer wrote while lexing `tok`, once, and fold its `warn`
34
40
  * into the label's rv.
@@ -10,7 +10,6 @@
10
10
  import type {
11
11
  HtmlCell,
12
12
  HtmlCellContent,
13
- HtmlImage,
14
13
  HtmlLabel,
15
14
  HtmlRow,
16
15
  HtmlTable,
@@ -22,8 +21,9 @@ import type {
22
21
  import { HtmlParseError } from './htmltable-types.js';
23
22
  import { StderrLines } from './htmltable-attr-warn.js';
24
23
  import type { ParseState } from './htmltable-parse-state.js';
25
- import { consume, emitEof, emitWarnings, peek } from './htmltable-parse-state.js';
26
- import { htmlErrorAtToken, tokenizeDeferred } from './htmltable-lex.js';
24
+ import { consume, consumedTag, emitEof, emitWarnings, peek } from './htmltable-parse-state.js';
25
+ import { HtmlLexError, htmlErrorAtToken, tokenizeDeferred } from './htmltable-lex.js';
26
+ import { scanCellImage } from './htmltable-parse-image.js';
27
27
  import type { FontState } from './htmltable-parse-font.js';
28
28
  import {
29
29
  fontItemProps, inlineFontState, isInlineTag, mergeFontState, tableFont, wrapperFont,
@@ -38,7 +38,7 @@ import {
38
38
  } from './htmltable-parse-attrs.js';
39
39
 
40
40
  /** bison's default message for an unexpected token. @see lib/common/htmlparse.y */
41
- const MSG_SYNTAX_ERROR = 'syntax error';
41
+ export const MSG_SYNTAX_ERROR = 'syntax error';
42
42
  /** @see lib/common/htmlparse.y:288 (table rule) */
43
43
  const MSG_TEXT_BEFORE_TABLE = 'Syntax error: non-space string used before <TABLE>';
44
44
  /** @see lib/common/htmlparse.y:298 (table rule) */
@@ -50,17 +50,25 @@ const nonSpace = (text: string): boolean => /[^ ]/.test(text);
50
50
  /** Text in `ctx->xb` that no token carried, which the table rule's nonSpace also reads. */
51
51
  const heldNonSpace = (tbl: Token | undefined): boolean => tbl?.type === 'open' && nonSpace(tbl.heldText ?? '');
52
52
 
53
+ /**
54
+ * `e` as C prints it once `ctx->error` is set: htmlerror and the expat path
55
+ * print nothing more (a silent HtmlParseError); only lexerror still does.
56
+ * @see lib/common/htmllex.c:htmlerror
57
+ */
58
+ const guarded = (s: ParseState, e: HtmlParseError): HtmlParseError =>
59
+ s.error === true && !(e instanceof HtmlLexError && e.unguarded) ? new HtmlParseError(e.tag) : e;
60
+
53
61
  /**
54
62
  * The parse failure C reports through `htmlerror` when the lexer last returned
55
63
  * `tok`. At end of input the deferred lexical error is what C would hit next.
56
64
  * A token without a recorded chunk yields a plain, silent HtmlParseError.
57
65
  * @see lib/common/htmllex.c:htmlerror
58
66
  */
59
- const parseError = (s: ParseState, tok: Token | undefined, message: string): HtmlParseError => {
67
+ export const parseError = (s: ParseState, tok: Token | undefined, message: string): HtmlParseError => {
60
68
  // The lexer already ran for the token the error is reported at.
61
69
  if (tok !== undefined) emitWarnings(s, tok);
62
70
  else emitEof(s);
63
- return (tok === undefined ? s.pending : htmlErrorAtToken(message, tok)) ?? new HtmlParseError(message);
71
+ return guarded(s, (tok === undefined ? s.pending : htmlErrorAtToken(message, tok)) ?? new HtmlParseError(message));
64
72
  };
65
73
 
66
74
  // ---------------------------------------------------------------------------
@@ -73,7 +81,7 @@ const parseError = (s: ParseState, tok: Token | undefined, message: string): Htm
73
81
  * syntax error at that token.
74
82
  * @see lib/common/htmlparse.y:br, image
75
83
  */
76
- const consumeClose = (s: ParseState, tag: string): void => {
84
+ export const consumeClose = (s: ParseState, tag: string): void => {
77
85
  const nxt = peek(s);
78
86
  if (nxt === undefined) return;
79
87
  if (nxt.type === 'close' && nxt.tag === tag) {
@@ -172,7 +180,7 @@ const fontTableWrapper = (s: ParseState): OpenToken | undefined => {
172
180
  };
173
181
 
174
182
  /** Consume strings; true when any is non-space (the table rule's nonSpace check). */
175
- const skipStrings = (s: ParseState): boolean => {
183
+ export const skipStrings = (s: ParseState): boolean => {
176
184
  let found = false;
177
185
  for (let t = peek(s); t?.type === 'text'; t = peek(s)) {
178
186
  consume(s);
@@ -210,29 +218,18 @@ const parseFontTable = (s: ParseState, open: OpenToken, fontStack: FontState[]):
210
218
  const rejectTableAfterTag = (s: ParseState, start: number): void => {
211
219
  const nxt = peek(s);
212
220
  if (nxt?.type !== 'open' || nxt.tag !== 'TABLE') return;
213
- if (s.tokens.slice(start, s.pos).some((t) => t.type !== 'text')) {
214
- throw parseError(s, nxt, MSG_SYNTAX_ERROR);
215
- }
221
+ if (consumedTag(s, start)) throw parseError(s, nxt, MSG_SYNTAX_ERROR);
216
222
  };
217
223
 
218
224
  // ---------------------------------------------------------------------------
219
225
  // Cell content helpers — mirrors htmlparse.y cell rule
220
226
  // ---------------------------------------------------------------------------
221
227
 
222
- const parseImgContent = (s: ParseState, t: OpenToken): HtmlImage => {
223
- consume(s);
224
- const img: HtmlImage = {
225
- kind: 'image',
226
- src: t.attrs['src'] ?? '',
227
- scale: t.attrs['scale'],
228
- };
229
- consumeClose(s, 'IMG');
230
- return img;
231
- };
232
-
233
228
  /** What a cell holds so far: C's cell has exactly one child. */
234
- interface CellScan {
229
+ export interface CellScan {
235
230
  kind: 'none' | 'text' | 'table' | 'fonttable' | 'image';
231
+ /** Index of the cell's first token. */
232
+ start: number;
236
233
  /** Non-space text before the nested table (checked when the table opens). */
237
234
  textNonSpace: boolean;
238
235
  /** Non-space text after the nested table (checked when the run ends). */
@@ -243,7 +240,6 @@ interface CellScan {
243
240
  const scanCellTable = (
244
241
  s: ParseState, t: Token, fontStack: FontState[], st: CellScan,
245
242
  ): HtmlCellContent[] => {
246
- if (st.kind === 'image' || st.kind === 'table') throw parseError(s, t, MSG_SYNTAX_ERROR);
247
243
  if (st.textNonSpace || heldNonSpace(t)) throw parseError(s, t, MSG_TEXT_BEFORE_TABLE);
248
244
  const tbl = parseTable(s, fontStack);
249
245
  st.kind = 'table';
@@ -269,18 +265,12 @@ const scanAfterTable = (s: ParseState, t: Token, st: CellScan): HtmlCellContent[
269
265
  return [];
270
266
  };
271
267
 
272
- /** `image` as the cell's only child. */
273
- const scanCellImage = (s: ParseState, t: OpenToken, st: CellScan): HtmlCellContent[] => {
274
- if (st.kind !== 'none') throw parseError(s, t, MSG_SYNTAX_ERROR);
275
- st.kind = 'image';
276
- return [parseImgContent(s, t)];
277
- };
278
-
279
268
  /** One step of `cell: T_cell (fonttable | fonttext | image) T_end_cell`. */
280
269
  const scanCellItem = (
281
270
  s: ParseState, t: Token, fontStack: FontState[], st: CellScan,
282
271
  ): HtmlCellContent[] => {
283
- if (st.kind === 'fonttable') throw parseError(s, t, MSG_SYNTAX_ERROR);
272
+ // After an image only the cell's close may come: its opt_space took the strings.
273
+ if (st.kind === 'fonttable' || st.kind === 'image') throw parseError(s, t, MSG_SYNTAX_ERROR);
284
274
  if (st.kind === 'table') return scanAfterTable(s, t, st);
285
275
  const wrapper = st.kind === 'none' ? fontTableWrapper(s) : undefined;
286
276
  if (wrapper !== undefined) {
@@ -289,7 +279,6 @@ const scanCellItem = (
289
279
  }
290
280
  if (t.type === 'open' && t.tag === 'TABLE') return scanCellTable(s, t, fontStack, st);
291
281
  if (t.type === 'open' && t.tag === 'IMG') return scanCellImage(s, t, st);
292
- if (st.kind === 'image') throw parseError(s, t, MSG_SYNTAX_ERROR);
293
282
  return scanCellText(s, t, fontStack, st);
294
283
  };
295
284
 
@@ -303,19 +292,18 @@ const endsCell = (s: ParseState, t: Token, st: CellScan): boolean => {
303
292
 
304
293
  const parseCellContent = (s: ParseState, fontStack: FontState[]): HtmlCellContent[] => {
305
294
  const content: HtmlCellContent[] = [];
306
- const st: CellScan = { kind: 'none', textNonSpace: false, afterNonSpace: false };
295
+ const st: CellScan = { kind: 'none', start: s.pos, textNonSpace: false, afterNonSpace: false };
307
296
  for (let t = peek(s); t !== undefined; t = peek(s)) {
308
297
  if (endsCell(s, t, st)) break;
309
298
  content.push(...scanCellItem(s, t, fontStack, st));
310
299
  }
311
300
  const nxt = peek(s);
312
301
  if (nxt?.type === 'close' && nxt.tag === 'TD') consume(s);
313
- // C models a cell child as a single object; the `TD table TD` rule discards
314
- // whitespace around a nested table, so a table IS the cell's sole content.
315
- // @see lib/common/htmltable.h:htmlcell_t.child
316
- const tbl = content.find((c) => c.kind === 'table');
317
- if (tbl !== undefined) return [tbl];
318
- return content;
302
+ // C models a cell child as a single object; the table and image rules take
303
+ // the strings around them (opt_space), so a table or image IS the cell's
304
+ // sole content. @see lib/common/htmltable.h:htmlcell_t.child
305
+ const sole = content.find((c) => c.kind === 'table' || c.kind === 'image');
306
+ return sole !== undefined ? [sole] : content;
319
307
  };
320
308
 
321
309
  /** @see lib/common/htmlparse.y:cell rule / lib/common/htmllex.c:mkCell */
@@ -547,10 +535,12 @@ const parseTokens = (s: ParseState): HtmlLabel => {
547
535
  return parseTextLabel(s, fontStack);
548
536
  };
549
537
 
550
- /** A parsed label and `ctx->warn`, which `make_html_label` ORs into its rv. */
538
+ /** A parsed label with `ctx->warn` and `ctx->error`, from which `clearHTMLlexer` makes parseHTML's rv. */
551
539
  export interface ParsedHtmlLabel {
552
540
  label: HtmlLabel;
553
541
  warn: boolean;
542
+ /** htmlerror printed but the parse went on: rv 3 with a label. */
543
+ error: boolean;
554
544
  }
555
545
 
556
546
  /**
@@ -566,11 +556,11 @@ export const parseHtmlLabelRv = (src: string, stderr: StderrLines): ParsedHtmlLa
566
556
  const s: ParseState = { tokens, pos: 0, pending: error, stderr, emitted: new WeakSet(), warn: false, eof };
567
557
  try {
568
558
  const label = parseTokens(s);
569
- if (error !== undefined) throw error;
570
- return { label, warn: s.warn === true };
559
+ if (error !== undefined) throw guarded(s, error);
560
+ return { label, warn: s.warn === true, error: s.error === true };
571
561
  } catch (e) {
572
562
  // Running off the truncated stream means C's lexer would have hit the error.
573
- if (error !== undefined && s.pos >= tokens.length) { emitEof(s); throw error; }
563
+ if (error !== undefined && s.pos >= tokens.length) { emitEof(s); throw guarded(s, error); }
574
564
  throw e;
575
565
  }
576
566
  };
@@ -20,6 +20,7 @@ import type { PolygonT } from './types.js';
20
20
  import type { InsideContext } from './splines-geom.js';
21
21
  import { polygonOutlineRing } from './poly-sizing.js';
22
22
  import { ccwrotatepf } from '../model/geom.js';
23
+ import { fdivOverflow } from '../util/overflow.js';
23
24
 
24
25
  /** Test if p0 and p1 are on the same side of the line L0-L1. @see shapes.c:same_side */
25
26
  export function sameSide(p0: Point, p1: Point, L0: Point, L1: Point): boolean {
@@ -60,7 +61,12 @@ function insideDims(n: Node, xsize: number, ysize: number):
60
61
  return { w, h, ow: 72 * n.info.outline_width || w, oh: 72 * n.info.outline_height || h };
61
62
  }
62
63
 
63
- /** @see lib/common/shapes.c:poly_inside (scale setup) */
64
+ /**
65
+ * C assigns `scalex = n_width` and then lets `fdiv_overflow` overwrite it
66
+ * with `n_width / xsize` when that quotient is finite (likewise `scaley`):
67
+ * `fdivOverflow(w, xsize) ?? w`.
68
+ * @see lib/common/shapes.c:poly_inside (scale setup, 2465-2469)
69
+ */
64
70
  function insideScale(n: Node, poly: PolygonT): InsideScale {
65
71
  // C swaps the node extents for flipped (LR/RL) layouts. @see poly_inside (GD_flip)
66
72
  const flip = n.root.info.flip === true;
@@ -74,8 +80,8 @@ function insideScale(n: Node, poly: PolygonT): InsideScale {
74
80
  const xsize = flip ? h : w;
75
81
  const ysize = flip ? w : h;
76
82
  return {
77
- scalex: xsize !== 0 ? w / xsize : w,
78
- scaley: ysize !== 0 ? h / ysize : h,
83
+ scalex: fdivOverflow(w, xsize) ?? w,
84
+ scaley: fdivOverflow(h, ysize) ?? h,
79
85
  boxURx: w / 2,
80
86
  boxURy: h / 2,
81
87
  };
@@ -85,8 +91,8 @@ function insideScale(n: Node, poly: PolygonT): InsideScale {
85
91
  const ysize = flip ? lwrw : n.info.ht;
86
92
  const { w, h, ow, oh } = insideDims(n, xsize, ysize);
87
93
  return {
88
- scalex: xsize !== 0 ? w / xsize : w,
89
- scaley: ysize !== 0 ? h / ysize : h,
94
+ scalex: fdivOverflow(w, xsize) ?? w,
95
+ scaley: fdivOverflow(h, ysize) ?? h,
90
96
  boxURx: ow / 2,
91
97
  boxURy: oh / 2,
92
98
  };
@@ -91,21 +91,39 @@ function expandByPoints(bb: Box, cp: Point[]): void {
91
91
  }
92
92
 
93
93
  /**
94
- * Expands bb to contain the cubic Bezier segment cp by adaptively refining the
95
- * segment to its true curve extent (not the control hull).
96
- * @see lib/common/emit.c:update_bb_bz
94
+ * How many times update_bb_bz attempts refinement of the control points.
95
+ * @see lib/common/emit.c:update_bb_bz (ATTEMPTS)
97
96
  */
98
- export function updateBbBz(bb: Box, cp: Point[]): void {
97
+ const UPDATE_BB_BZ_ATTEMPTS = 10;
98
+
99
+ /**
100
+ * Expands bb by the segment cp, halving it until it is sufficiently refined.
101
+ * A segment still unrefined when `recurse` reaches 0 leaves bb as it is
102
+ * (graphviz 16.1.1, upstream issue 2780: huge coordinates never refine).
103
+ * @see lib/common/emit.c:update_bb_bz_core
104
+ */
105
+ function updateBbBzCore(bb: Box, cp: Point[], recurse: number): void {
99
106
  if (!anyOutside(bb, cp)) return;
100
107
  if (checkControlPoints(cp)) {
101
108
  expandByPoints(bb, cp);
102
109
  return;
103
110
  }
111
+ if (recurse === 0) return;
104
112
  const left: Point[] = [];
105
113
  const right: Point[] = [];
106
114
  evalBezier(cp, 0.5, left, right);
107
- updateBbBz(bb, left);
108
- updateBbBz(bb, right);
115
+ updateBbBzCore(bb, left, recurse - 1);
116
+ updateBbBzCore(bb, right, recurse - 1);
117
+ }
118
+
119
+ /**
120
+ * Expands bb to contain the cubic Bezier segment cp by adaptively refining the
121
+ * segment to its true curve extent (not the control hull). Refinement stops
122
+ * after UPDATE_BB_BZ_ATTEMPTS levels (upstream issue 2780).
123
+ * @see lib/common/emit.c:update_bb_bz
124
+ */
125
+ export function updateBbBz(bb: Box, cp: Point[]): void {
126
+ updateBbBzCore(bb, cp, UPDATE_BB_BZ_ATTEMPTS);
109
127
  }
110
128
 
111
129
  // ---------------------------------------------------------------------------