@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.
- package/dist/common/compass-port.d.ts.map +1 -1
- package/dist/common/graph-init.d.ts.map +1 -1
- package/dist/common/htmltable-label.d.ts.map +1 -1
- package/dist/common/htmltable-lex.d.ts +3 -1
- package/dist/common/htmltable-lex.d.ts.map +1 -1
- package/dist/common/htmltable-parse-image.d.ts +23 -0
- package/dist/common/htmltable-parse-image.d.ts.map +1 -0
- package/dist/common/htmltable-parse-state.d.ts +4 -0
- package/dist/common/htmltable-parse-state.d.ts.map +1 -1
- package/dist/common/htmltable-parse.d.ts +33 -2
- package/dist/common/htmltable-parse.d.ts.map +1 -1
- package/dist/common/poly-inside.d.ts.map +1 -1
- package/dist/common/splines-geom.d.ts +2 -1
- package/dist/common/splines-geom.d.ts.map +1 -1
- package/dist/common/splines-routespl.d.ts +3 -0
- package/dist/common/splines-routespl.d.ts.map +1 -1
- package/dist/index.js +21301 -21229
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/classify.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
- package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
- package/dist/layout/dot/edge-route-chain.d.ts +20 -16
- package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
- package/dist/layout/dot/flat.d.ts +22 -7
- package/dist/layout/dot/flat.d.ts.map +1 -1
- package/dist/layout/dot/mincross-flat.d.ts +10 -1
- package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
- package/dist/layout/dot/mincross.d.ts +6 -1
- package/dist/layout/dot/mincross.d.ts.map +1 -1
- package/dist/layout/dot/ns-subtree.d.ts +9 -6
- package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
- package/dist/layout/dot/pack-components.d.ts +4 -3
- package/dist/layout/dot/pack-components.d.ts.map +1 -1
- package/dist/layout/dot/position-aux.d.ts +62 -20
- package/dist/layout/dot/position-aux.d.ts.map +1 -1
- package/dist/layout/dot/position-bbox.d.ts.map +1 -1
- package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
- package/dist/layout/dot/position.d.ts.map +1 -1
- package/dist/layout/dot/rank-dot2.d.ts +7 -25
- package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
- package/dist/layout/dot/self-loop.d.ts +11 -4
- package/dist/layout/dot/self-loop.d.ts.map +1 -1
- package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
- package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
- package/dist/layout/dot/splines-route.d.ts +6 -3
- package/dist/layout/dot/splines-route.d.ts.map +1 -1
- package/dist/layout/dot/straight-edges.d.ts.map +1 -1
- package/dist/layout/fdp/tlayout.d.ts +3 -0
- package/dist/layout/fdp/tlayout.d.ts.map +1 -1
- package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
- package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
- package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
- package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
- package/dist/layout/neato/conjgrad.d.ts +7 -6
- package/dist/layout/neato/conjgrad.d.ts.map +1 -1
- package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
- package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
- package/dist/layout/neato/matrix-ops.d.ts +0 -6
- package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
- package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
- package/dist/model/rankEntry.d.ts +3 -1
- package/dist/model/rankEntry.d.ts.map +1 -1
- package/dist/ortho/index.d.ts +0 -1
- package/dist/ortho/index.d.ts.map +1 -1
- package/dist/ortho/partition.d.ts +2 -4
- package/dist/ortho/partition.d.ts.map +1 -1
- package/dist/pathplan/route.d.ts +93 -0
- package/dist/pathplan/route.d.ts.map +1 -1
- package/dist/render/dot/agwrite.d.ts +21 -9
- package/dist/render/dot/agwrite.d.ts.map +1 -1
- package/dist/render/dot/types.d.ts +7 -2
- package/dist/render/dot/types.d.ts.map +1 -1
- package/dist/render.js +21301 -21229
- package/dist/render.js.map +4 -4
- package/dist/util/overflow.d.ts +37 -0
- package/dist/util/overflow.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/common/compass-port.ts +36 -20
- package/src/common/graph-init.ts +11 -1
- package/src/common/htmltable-label.ts +9 -4
- package/src/common/htmltable-lex.ts +5 -2
- package/src/common/htmltable-parse-image.ts +69 -0
- package/src/common/htmltable-parse-state.ts +6 -0
- package/src/common/htmltable-parse.ts +34 -44
- package/src/common/poly-inside.ts +11 -5
- package/src/common/splines-geom.ts +24 -6
- package/src/common/splines-routespl.ts +32 -0
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
- package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
- package/src/layout/dot/classify.ts +5 -2
- package/src/layout/dot/edge-route-chain-views.ts +120 -0
- package/src/layout/dot/edge-route-chain.ts +103 -117
- package/src/layout/dot/edge-route-faithful.ts +20 -5
- package/src/layout/dot/flat.ts +38 -17
- package/src/layout/dot/mincross-flat.ts +15 -5
- package/src/layout/dot/mincross.ts +6 -2
- package/src/layout/dot/ns-subtree.ts +11 -7
- package/src/layout/dot/pack-components.ts +6 -4
- package/src/layout/dot/position-aux.ts +112 -39
- package/src/layout/dot/position-bbox.ts +14 -1
- package/src/layout/dot/position-ycoords.ts +7 -1
- package/src/layout/dot/position.ts +4 -1
- package/src/layout/dot/rank-dot2.ts +13 -94
- package/src/layout/dot/self-loop.ts +29 -11
- package/src/layout/dot/splines-flat-multi.ts +12 -4
- package/src/layout/dot/splines-route.ts +10 -11
- package/src/layout/dot/straight-edges.ts +5 -3
- package/src/layout/fdp/tlayout.ts +6 -5
- package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
- package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
- package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
- package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
- package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
- package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
- package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
- package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
- package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
- package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
- package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
- package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
- package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
- package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
- package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
- package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
- package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
- package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
- package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
- package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
- package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
- package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
- package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
- package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
- package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
- package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
- package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
- package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
- package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
- package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
- package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
- package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
- package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
- package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
- package/src/layout/neato/conjgrad.ts +38 -35
- package/src/layout/neato/matrix-ops-dense.ts +2 -20
- package/src/layout/neato/matrix-ops.ts +0 -20
- package/src/layout/neato/quad-prog-vpsc.ts +7 -5
- package/src/layout/neato/smart-ini-x.ts +15 -15
- package/src/layout/neato/stress-subspace.ts +5 -5
- package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
- package/src/model/rankEntry.ts +3 -1
- package/src/ortho/index.ts +0 -1
- package/src/ortho/partition.ts +10 -22
- package/src/pathplan/route.ts +14 -4
- package/src/render/dot/agwrite.ts +35 -15
- package/src/render/dot/types.ts +7 -2
- package/src/util/overflow.ts +74 -0
package/src/ortho/partition.ts
CHANGED
|
@@ -7,23 +7,19 @@
|
|
|
7
7
|
* (via perp()). Intersection of the two decompositions yields cells
|
|
8
8
|
* bounded on all four sides.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* The segment permutation draws from the process-global libc rand() stream
|
|
11
|
+
* (graphviz 16.1.1, b99490ece): partition no longer seeds srand48(173).
|
|
11
12
|
*
|
|
12
13
|
* @see lib/ortho/partition.c
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
|
-
import {
|
|
16
|
+
import { gvPermutation } from "../common/crand.js";
|
|
16
17
|
import type { OrthoBox, OrthoPoint, Cell } from "./types.js";
|
|
17
18
|
import {
|
|
18
19
|
constructTrapezoids, fpEqual, greaterThan, isValidTrap, C_EPS, equalTo,
|
|
19
20
|
} from "./trapezoid.js";
|
|
20
21
|
import type { SegmentT, TrapT } from "./trapezoid.js";
|
|
21
22
|
|
|
22
|
-
/** Fixed RNG seed — matches lib/ortho/partition.c:srand48(173) */
|
|
23
|
-
const SEED = 173;
|
|
24
|
-
|
|
25
|
-
export { SEED };
|
|
26
|
-
|
|
27
23
|
const NPOINTS = 4;
|
|
28
24
|
|
|
29
25
|
/** @see lib/ortho/partition.c:#define TR_FROM_UP/TR_FROM_DN */
|
|
@@ -86,20 +82,14 @@ class PartitionHelper {
|
|
|
86
82
|
}
|
|
87
83
|
|
|
88
84
|
/**
|
|
89
|
-
* Generate a random permutation of the segments 1..n
|
|
90
|
-
*
|
|
85
|
+
* Generate a random permutation of the segments 1..n: gv_permutation's
|
|
86
|
+
* Fisher-Yates shuffle over the global libc rand() stream, made 1-based.
|
|
91
87
|
* @see lib/ortho/partition.c:generateRandomOrdering
|
|
92
88
|
*/
|
|
93
89
|
static generateRandomOrdering(n: number): number[] {
|
|
94
|
-
const permute
|
|
95
|
-
|
|
96
|
-
for (let i = 0; i < n; i++)
|
|
97
|
-
// C: j = (size_t)((double)i + drand48() * (double)(n - i));
|
|
98
|
-
const j = Math.floor(i + drand48() * (n - i));
|
|
99
|
-
if (j !== i) {
|
|
100
|
-
const tmp = permute[i]; permute[i] = permute[j]; permute[j] = tmp;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
90
|
+
const permute = gvPermutation(n);
|
|
91
|
+
// make indexing 1-based
|
|
92
|
+
for (let i = 0; i < n; i++) permute[i]!++;
|
|
103
93
|
return permute;
|
|
104
94
|
}
|
|
105
95
|
|
|
@@ -271,10 +261,8 @@ export function partition(cells: Cell[], bb: OrthoBox): OrthoBox[] | null {
|
|
|
271
261
|
const h = PartitionHelper;
|
|
272
262
|
const nsegs = 4 * (cells.length + 1);
|
|
273
263
|
|
|
274
|
-
// C:
|
|
275
|
-
//
|
|
276
|
-
srand48(SEED);
|
|
277
|
-
|
|
264
|
+
// C: the two generateRandomOrdering calls share the continuing rand()
|
|
265
|
+
// stream (partition.c:677, :693).
|
|
278
266
|
const hSeg = h.genSegments(cells, bb, false);
|
|
279
267
|
const hPerm = h.generateRandomOrdering(nsegs);
|
|
280
268
|
const hTr = constructTrapezoids(nsegs, hSeg, hPerm);
|
package/src/pathplan/route.ts
CHANGED
|
@@ -15,7 +15,8 @@ interface LineCoeff { xc0: number; xc1: number; yc0: number; yc1: number; }
|
|
|
15
15
|
interface RootAccum { roots: number[]; n: number; }
|
|
16
16
|
interface RouteState { ops: Point[]; barriers: Edge[]; }
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/** @internal — exported for route.branch.test.ts */
|
|
19
|
+
export class RouteHelper {
|
|
19
20
|
static B0(t: number): number { const u = 1-t; return u*u*u; }
|
|
20
21
|
static B1(t: number): number { const u = 1-t; return 3*t*u*u; }
|
|
21
22
|
static B2(t: number): number { const u = 1-t; return 3*t*t*u; }
|
|
@@ -71,6 +72,15 @@ class RouteHelper {
|
|
|
71
72
|
c[0] = v0;
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
/**
|
|
76
|
+
* `a == b` within a tolerance (16.1.1 `d3ab9ba47`; the same 1e-7 as solve3).
|
|
77
|
+
* @see lib/pathplan/route.c:eq
|
|
78
|
+
*/
|
|
79
|
+
static eq(a: number, b: number): boolean {
|
|
80
|
+
const EPS = 1e-7;
|
|
81
|
+
return Math.abs(a - b) < EPS;
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
static addRoot(root: number, acc: RootAccum): void {
|
|
75
85
|
if (root >= 0 && root <= 1) { acc.roots[acc.n] = root; acc.n++; }
|
|
76
86
|
}
|
|
@@ -91,7 +101,7 @@ class RouteHelper {
|
|
|
91
101
|
} else {
|
|
92
102
|
for (let i = 0; i < xn; i++)
|
|
93
103
|
for (let j = 0; j < yn; j++)
|
|
94
|
-
if (xr[i]
|
|
104
|
+
if (RouteHelper.eq(xr[i], yr[j])) RouteHelper.addRoot(xr[i], acc);
|
|
95
105
|
}
|
|
96
106
|
return acc.n;
|
|
97
107
|
}
|
|
@@ -144,8 +154,8 @@ class RouteHelper {
|
|
|
144
154
|
yc0: lps[0].y, yc1: lps[1].y - lps[0].y,
|
|
145
155
|
};
|
|
146
156
|
const acc: RootAccum = { roots, n: 0 };
|
|
147
|
-
if (lc.xc1
|
|
148
|
-
if (lc.yc1
|
|
157
|
+
if (RouteHelper.eq(lc.xc1, 0)) {
|
|
158
|
+
if (RouteHelper.eq(lc.yc1, 0)) return RouteHelper.silBothZero(sps, lc, acc);
|
|
149
159
|
return RouteHelper.silXzeroYnonzero(sps, lc, acc);
|
|
150
160
|
}
|
|
151
161
|
return RouteHelper.silGeneral(sps, lc, acc);
|
|
@@ -61,19 +61,22 @@ export abstract class DotWriterBase {
|
|
|
61
61
|
/**
|
|
62
62
|
* Serialize the whole laid-out graph to xdot DOT text — a faithful port of
|
|
63
63
|
* cgraph's agwrite (lib/cgraph/write.c). Recurses the subgraph tree
|
|
64
|
-
* (write_subgs/write_body)
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
64
|
+
* (write_subgs/write_body). A node is scoped to the subgraph(s) it belongs
|
|
65
|
+
* to via preorder numbers (write_node_test), and is re-emitted bare (no
|
|
66
|
+
* attrs) on any scope after the first (attrs_written). An edge is written
|
|
67
|
+
* once: each body pends its out-edges during the node walk and writes them
|
|
68
|
+
* after it in creation order (write_edges), and an edge already written is
|
|
69
|
+
* never pended again, so no later scope re-declares it (graphviz 16.1.1).
|
|
69
70
|
* @see lib/cgraph/write.c:agwrite
|
|
71
|
+
* @see lib/cgraph/write.c:before_write
|
|
70
72
|
*/
|
|
71
73
|
protected serialize(g: Graph): string {
|
|
72
74
|
const ctx: SerCtx = {
|
|
73
75
|
out: [],
|
|
74
76
|
preorder: new Map<Graph, number>(),
|
|
75
77
|
nodeLW: new Map<Node, number>(),
|
|
76
|
-
|
|
78
|
+
edgesTodo: new Map<number, Edge>(),
|
|
79
|
+
edgesDone: new Set<number>(),
|
|
77
80
|
attrsWritten: new Set<Node | Edge>(),
|
|
78
81
|
level: 0,
|
|
79
82
|
};
|
|
@@ -260,7 +263,10 @@ export abstract class DotWriterBase {
|
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
|
|
263
|
-
/**
|
|
266
|
+
/** Subgraphs, then this scope's nodes, then the edges the node walk pended.
|
|
267
|
+
* The walk still writes an out-edge's head node right after its tail, but
|
|
268
|
+
* the edge itself waits for writeEdges unless an earlier body wrote it.
|
|
269
|
+
* @see lib/cgraph/write.c:write_body */
|
|
264
270
|
private writeBody(g: Graph, ctx: SerCtx): void {
|
|
265
271
|
this.writeSubgs(g, ctx);
|
|
266
272
|
// agfstnode/agnxtnode walk a subgraph's node set in AGSEQ (root creation)
|
|
@@ -275,9 +281,24 @@ export abstract class DotWriterBase {
|
|
|
275
281
|
this.writeNode(g, e.head, ctx);
|
|
276
282
|
prev = e.head;
|
|
277
283
|
}
|
|
278
|
-
|
|
284
|
+
// pend this edge to be emitted later
|
|
285
|
+
if (!ctx.edgesDone.has(e.seq)) ctx.edgesTodo.set(e.seq, e);
|
|
279
286
|
}
|
|
280
287
|
}
|
|
288
|
+
// flush pending edges to the output
|
|
289
|
+
this.writeEdges(g, ctx);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Write the pending edges in ascending `Edge.seq` (the C walks a Dtoset
|
|
293
|
+
* keyed on AGSEQ), mark each done, and empty the set for the next body.
|
|
294
|
+
* @see lib/cgraph/write.c:write_edges */
|
|
295
|
+
private writeEdges(g: Graph, ctx: SerCtx): void {
|
|
296
|
+
const seqs = [...ctx.edgesTodo.keys()].sort((a, b) => a - b);
|
|
297
|
+
for (const seq of seqs) {
|
|
298
|
+
this.writeEdge(g, ctx.edgesTodo.get(seq)!, ctx);
|
|
299
|
+
ctx.edgesDone.add(seq);
|
|
300
|
+
}
|
|
301
|
+
ctx.edgesTodo.clear();
|
|
281
302
|
}
|
|
282
303
|
|
|
283
304
|
/** @see write.c:write_node_test — every xdot node carries pos/size, so it is
|
|
@@ -299,11 +320,6 @@ export abstract class DotWriterBase {
|
|
|
299
320
|
return n.name;
|
|
300
321
|
}
|
|
301
322
|
|
|
302
|
-
/** @see write.c:write_edge_test */
|
|
303
|
-
private writeEdgeTest(g: Graph, e: Edge, ctx: SerCtx): boolean {
|
|
304
|
-
return (ctx.edgeLW.get(e) ?? 0) < ctx.preorder.get(g)!;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
323
|
/** @see write.c:write_node */
|
|
308
324
|
private writeNode(g: Graph, n: Node, ctx: SerCtx): void {
|
|
309
325
|
let s = this.indent(ctx) + xdotId(this.emitNodeName(n));
|
|
@@ -315,7 +331,6 @@ export abstract class DotWriterBase {
|
|
|
315
331
|
ctx.nodeLW.set(n, ctx.preorder.get(g)!);
|
|
316
332
|
}
|
|
317
333
|
|
|
318
|
-
/** @see write.c:write_edge — attrs only on first emission, bare thereafter. */
|
|
319
334
|
/**
|
|
320
335
|
* The `:port` / `:port:compass` suffix C writes after an endpoint name.
|
|
321
336
|
*
|
|
@@ -341,6 +356,12 @@ export abstract class DotWriterBase {
|
|
|
341
356
|
return ':' + agstrcanonText(val.slice(0, i)) + ':' + agstrcanonText(val.slice(i + 1));
|
|
342
357
|
}
|
|
343
358
|
|
|
359
|
+
/** One edge statement. The C's `else` arm (write_edge_name: a bare `[key=…]`
|
|
360
|
+
* for an edge whose attributes were already written) is not ported: since
|
|
361
|
+
* 16.1.1 edges_done makes write_body write each edge once per agwrite, and
|
|
362
|
+
* before_write's set_attrwf clears every flag first, so the arm cannot run.
|
|
363
|
+
* The attrsWritten gate stays, as the C's `if (!attrs_written(e))` does.
|
|
364
|
+
* @see lib/cgraph/write.c:write_edge */
|
|
344
365
|
private writeEdge(g: Graph, e: Edge, ctx: SerCtx): void {
|
|
345
366
|
const conn = edgeConnector(isDirected(g));
|
|
346
367
|
let s = this.indent(ctx) + xdotId(this.emitNodeName(e.tail)) +
|
|
@@ -351,7 +372,6 @@ export abstract class DotWriterBase {
|
|
|
351
372
|
ctx.attrsWritten.add(e);
|
|
352
373
|
}
|
|
353
374
|
ctx.out.push(s + ';\n');
|
|
354
|
-
ctx.edgeLW.set(e, ctx.preorder.get(g)!);
|
|
355
375
|
}
|
|
356
376
|
|
|
357
377
|
/** Root-graph attribute block: `_draw_`, `_ldraw_`, `bb`, `xdotversion`. */
|
package/src/render/dot/types.ts
CHANGED
|
@@ -23,8 +23,13 @@ export interface SerCtx {
|
|
|
23
23
|
preorder: Map<Graph, number>;
|
|
24
24
|
/** node → preorder of the subgraph it was last written in (node_last_written). */
|
|
25
25
|
nodeLW: Map<Node, number>;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/** Edges the current body has pended, keyed on `Edge.seq` (AGSEQ), which dedupes as the C's
|
|
27
|
+
* ordered dictionary does. Empty at the start of every body's node walk.
|
|
28
|
+
* @see lib/cgraph/write.c:info_t (edges_todo) */
|
|
29
|
+
edgesTodo: Map<number, Edge>;
|
|
30
|
+
/** `Edge.seq` of every edge already written in this agwrite.
|
|
31
|
+
* @see lib/cgraph/write.c:info_t (edges_done) */
|
|
32
|
+
edgesDone: Set<number>;
|
|
28
33
|
/** objects whose attributes have already been emitted (AGATTRWF/attrs_written). */
|
|
29
34
|
attrsWritten: Set<Node | Edge>;
|
|
30
35
|
/** current indentation depth. */
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Overflow-checked arithmetic helpers.
|
|
4
|
+
*
|
|
5
|
+
* @see lib/util/overflow.h
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// C's INT_MAX / INT_MIN for a 32-bit int.
|
|
9
|
+
const INT_MAX = 2_147_483_647;
|
|
10
|
+
const INT_MIN = -2_147_483_648;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add two integers, clamping to lower and upper type bounds.
|
|
14
|
+
*
|
|
15
|
+
* Returns the sum `a + b`, or `INT_MAX`/`INT_MIN` on overflow/underflow. C's
|
|
16
|
+
* operands are `int`; the port applies the same three branches to its numbers
|
|
17
|
+
* as they are, with no int32 wrap of the inputs.
|
|
18
|
+
* @see lib/util/overflow.h:sadd_saturate
|
|
19
|
+
*/
|
|
20
|
+
export function saddSaturate(a: number, b: number): number {
|
|
21
|
+
// overflow?
|
|
22
|
+
if (b > 0 && INT_MAX - b < a) {
|
|
23
|
+
return INT_MAX;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// underflow?
|
|
27
|
+
if (b < 0 && INT_MIN - b > a) {
|
|
28
|
+
return INT_MIN;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return a + b;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Divide two double floating-point values, checking for overflow.
|
|
36
|
+
*
|
|
37
|
+
* Returns the quotient `n / d`, or `null` where C returns `true` and leaves
|
|
38
|
+
* `*res` as it was: the quotient is not finite (a zero or subnormal divisor,
|
|
39
|
+
* a non-finite operand, or a result past `DBL_MAX`). A call site writes C's
|
|
40
|
+
* "assign the fallback, then overwrite on success" as `fdivOverflow(n, d) ??
|
|
41
|
+
* fallback`; a zero quotient is a result, and `??` keeps it.
|
|
42
|
+
* @see lib/util/overflow.h:fdiv_overflow
|
|
43
|
+
*/
|
|
44
|
+
export function fdivOverflow(n: number, d: number): number | null {
|
|
45
|
+
const r = n / d;
|
|
46
|
+
|
|
47
|
+
// did we overflow?
|
|
48
|
+
if (!Number.isFinite(r)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return r;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Divide two floating-point values, checking for overflow.
|
|
57
|
+
*
|
|
58
|
+
* The `float` twin of {@link fdivOverflow}. C's parameters and quotient are
|
|
59
|
+
* `float`, so the operands and the quotient are rounded to float32: a
|
|
60
|
+
* quotient past `FLT_MAX` is an overflow here though it is finite as a
|
|
61
|
+
* double. Dividing two float32 values in double and rounding once gives
|
|
62
|
+
* IEEE single division's result (53 >= 2 * 24 + 2 bits).
|
|
63
|
+
* @see lib/util/overflow.h:fdivf_overflow
|
|
64
|
+
*/
|
|
65
|
+
export function fdivfOverflow(n: number, d: number): number | null {
|
|
66
|
+
const r = Math.fround(Math.fround(n) / Math.fround(d));
|
|
67
|
+
|
|
68
|
+
// did we overflow?
|
|
69
|
+
if (!Number.isFinite(r)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return r;
|
|
74
|
+
}
|