@ac-kit/math-graph 0.1.0 → 0.2.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.
- package/CHANGELOG.md +92 -0
- package/README.md +42 -16
- package/dist/layout/_force-forces.d.ts +140 -16
- package/dist/layout/_force-forces.d.ts.map +1 -1
- package/dist/layout/_force-forces.js +1204 -122
- package/dist/layout/_force-forces.js.map +1 -1
- package/dist/layout/_hierarchy-table.js.map +1 -1
- package/dist/layout/_layer-order.d.ts +52 -10
- package/dist/layout/_layer-order.d.ts.map +1 -1
- package/dist/layout/_layer-order.js +565 -73
- package/dist/layout/_layer-order.js.map +1 -1
- package/dist/layout/_layered-rank.d.ts +8 -4
- package/dist/layout/_layered-rank.d.ts.map +1 -1
- package/dist/layout/_layered-rank.js +113 -20
- package/dist/layout/_layered-rank.js.map +1 -1
- package/dist/layout/_treemap-tiling.d.ts +13 -2
- package/dist/layout/_treemap-tiling.d.ts.map +1 -1
- package/dist/layout/_treemap-tiling.js +70 -10
- package/dist/layout/_treemap-tiling.js.map +1 -1
- package/dist/layout/create-force-step.d.ts +39 -24
- package/dist/layout/create-force-step.d.ts.map +1 -1
- package/dist/layout/create-force-step.js +45 -12
- package/dist/layout/create-force-step.js.map +1 -1
- package/dist/layout/layered-layout.d.ts +15 -2
- package/dist/layout/layered-layout.d.ts.map +1 -1
- package/dist/layout/layered-layout.js +5 -1
- package/dist/layout/layered-layout.js.map +1 -1
- package/dist/layout/sankey-layout.d.ts +10 -1
- package/dist/layout/sankey-layout.d.ts.map +1 -1
- package/dist/layout/sankey-layout.js +5 -0
- package/dist/layout/sankey-layout.js.map +1 -1
- package/dist/layout/tidy-tree-layout.js.map +1 -1
- package/dist/layout/treemap-layout.d.ts +14 -5
- package/dist/layout/treemap-layout.d.ts.map +1 -1
- package/dist/layout/treemap-layout.js +13 -8
- package/dist/layout/treemap-layout.js.map +1 -1
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,97 @@
|
|
|
1
1
|
# @ac-kit/math-graph
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0b4fe43: `forceDirectedLayout` is a d3-force-style simulation that no longer inherits
|
|
8
|
+
d3-force's Barnes–Hut limits. A node's own charge is never applied (a cell
|
|
9
|
+
holding the node is always opened), `distanceMax` applies to each body (a cell
|
|
10
|
+
straddling it is opened), and the positive and negative charges of a cell are
|
|
11
|
+
kept apart, so each monopole's error is bounded as for same-sign charges (a
|
|
12
|
+
node's error relative to its unsigned contributions, Σ |q| / d, not to its net
|
|
13
|
+
force) and a cell whose charges sum to zero still acts. Every force and the
|
|
14
|
+
integration keep positions and velocities finite for any finite inputs and
|
|
15
|
+
options, across the whole binary64 range: differences, sums, means, squares,
|
|
16
|
+
products, the `distanceMin` clamp, ratios and shares are scaled by powers of
|
|
17
|
+
two where they would leave the doubles (each end's share applied before
|
|
18
|
+
scaling back), positions beyond ±1e150 are indexed in a scaled quadtree, and
|
|
19
|
+
a position or velocity whose exact value lies beyond the doubles saturates at
|
|
20
|
+
±`Number.MAX_VALUE`, in either approximation and with `compatibility:
|
|
21
|
+
"d3-force"`. Collisions never
|
|
22
|
+
miss a pair a node was pushed into earlier in the same pass nor one the active
|
|
23
|
+
node moved into by its own pushes, every node of a chain of coincident nodes
|
|
24
|
+
collides, and a self-link exerts no force. `compatibility: "d3-force"`
|
|
25
|
+
reproduces d3-force 3 instead, quirks included: with the same random source the
|
|
26
|
+
Barnes–Hut mode then matches d3-force's (same θ) and the `"exact"` mode
|
|
27
|
+
d3-force with θ = 0, to rounding. `createForceStep` allocates nothing per step
|
|
28
|
+
once warmed up.
|
|
29
|
+
- 0b4fe43: `layeredLayout` reduces crossings by sweeps, transposition and, with the new
|
|
30
|
+
`orderingEffort: "thorough"` (the default), by sifting each vertex to its best
|
|
31
|
+
slot, which leaves the local minima the sweeps stop in. It never has more
|
|
32
|
+
weighted crossings than `orderingEffort: "fast"`, which skips the sifting; where
|
|
33
|
+
rounded counts are too close to tell two orders apart, the exact weighted totals
|
|
34
|
+
decide. Each layer pair's weighted count is the exact `Σ wᵢ·wⱼ` over its
|
|
35
|
+
crossing pairs rounded once, for any finite weights ≥ 0, at the cost of the
|
|
36
|
+
compensated count it replaces wherever a rigorous bound certifies that
|
|
37
|
+
rounding. Network-simplex ranking charges the work budget, and yields, before each
|
|
38
|
+
exact scan that settles a cut value. `sankeyLayout` accepts `ordering:
|
|
39
|
+
"crossings"` to order its nodes with the layered crossing reduction and its
|
|
40
|
+
`orderingEffort`, instead of d3-sankey's relaxation.
|
|
41
|
+
- 0b4fe43: `treemapLayout` reserves a parent's own value in every tiling, so the area of a
|
|
42
|
+
cell is proportional to its value and small children keep their share beside a
|
|
43
|
+
huge one. `compatibility: "d3-hierarchy"` reproduces d3-hierarchy's binary
|
|
44
|
+
tiling, which does not.
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [0b4fe43]
|
|
49
|
+
- Updated dependencies [0b4fe43]
|
|
50
|
+
- Updated dependencies [0b4fe43]
|
|
51
|
+
- Updated dependencies [0b4fe43]
|
|
52
|
+
- Updated dependencies [0b4fe43]
|
|
53
|
+
- Updated dependencies [0b4fe43]
|
|
54
|
+
- Updated dependencies [0b4fe43]
|
|
55
|
+
- Updated dependencies [0b4fe43]
|
|
56
|
+
- Updated dependencies [0b4fe43]
|
|
57
|
+
- Updated dependencies [0b4fe43]
|
|
58
|
+
- Updated dependencies [0b4fe43]
|
|
59
|
+
- Updated dependencies [0b4fe43]
|
|
60
|
+
- Updated dependencies [0b4fe43]
|
|
61
|
+
- Updated dependencies [0b4fe43]
|
|
62
|
+
- Updated dependencies [0b4fe43]
|
|
63
|
+
- Updated dependencies [0b4fe43]
|
|
64
|
+
- Updated dependencies [0b4fe43]
|
|
65
|
+
- Updated dependencies [0b4fe43]
|
|
66
|
+
- Updated dependencies [0b4fe43]
|
|
67
|
+
- Updated dependencies [0b4fe43]
|
|
68
|
+
- Updated dependencies [0b4fe43]
|
|
69
|
+
- Updated dependencies [0b4fe43]
|
|
70
|
+
- Updated dependencies [0b4fe43]
|
|
71
|
+
- Updated dependencies [0b4fe43]
|
|
72
|
+
- Updated dependencies [0b4fe43]
|
|
73
|
+
- Updated dependencies [0b4fe43]
|
|
74
|
+
- Updated dependencies [0b4fe43]
|
|
75
|
+
- Updated dependencies [0b4fe43]
|
|
76
|
+
- Updated dependencies [0b4fe43]
|
|
77
|
+
- Updated dependencies [0b4fe43]
|
|
78
|
+
- Updated dependencies [0b4fe43]
|
|
79
|
+
- Updated dependencies [0b4fe43]
|
|
80
|
+
- Updated dependencies [0b4fe43]
|
|
81
|
+
- Updated dependencies [0b4fe43]
|
|
82
|
+
- Updated dependencies [0b4fe43]
|
|
83
|
+
- Updated dependencies [0b4fe43]
|
|
84
|
+
- Updated dependencies [0b4fe43]
|
|
85
|
+
- Updated dependencies [0b4fe43]
|
|
86
|
+
- Updated dependencies [0b4fe43]
|
|
87
|
+
- Updated dependencies [0b4fe43]
|
|
88
|
+
- @ac-kit/algo@0.6.0
|
|
89
|
+
- @ac-kit/core@0.13.0
|
|
90
|
+
- @ac-kit/data@0.5.0
|
|
91
|
+
- @ac-kit/math-geometry@0.4.0
|
|
92
|
+
- @ac-kit/math-linear@0.4.0
|
|
93
|
+
- @ac-kit/math-scalar@0.4.0
|
|
94
|
+
|
|
3
95
|
## 0.1.0
|
|
4
96
|
|
|
5
97
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -41,24 +41,37 @@ Network layouts take explicit links (`sourceOf`, `targetOf` return indices into
|
|
|
41
41
|
`nodes`) and return `Float64Array` buffers in input order. The force layout
|
|
42
42
|
applies link, many-body (Barnes–Hut by default, `"exact"` on request),
|
|
43
43
|
collision, gravity and centring forces, then velocity decay, as d3-force does.
|
|
44
|
-
|
|
45
|
-
(same θ) and `"exact"` mode matches d3-force with θ = 0, to rounding. `random`
|
|
46
|
-
is required: pass a seeded generator such as `mulberry32(seed)`, which
|
|
44
|
+
`random` is required: pass a seeded generator such as `mulberry32(seed)`, which
|
|
47
45
|
separates coincident nodes reproducibly.
|
|
48
46
|
|
|
49
|
-
Barnes–Hut
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
Barnes–Hut is a bounded approximation of `"exact"` whose error tends to 0 with
|
|
48
|
+
θ (Barnes and Hut 1986). A cell is never summarised while the node lies inside
|
|
49
|
+
it, enlarged by 20 % as in GADGET-2 (Springel 2005), so a node never feels its
|
|
50
|
+
own charge however large θ is, the failure Salmon and Warren (1994) show
|
|
51
|
+
unbounds the plain criterion. Each cell keeps its positive and its negative
|
|
52
|
+
charges as two monopoles, so each monopole's error is bounded as for same-sign
|
|
53
|
+
charges and a cell whose charges sum to zero still acts: a node's error is
|
|
54
|
+
bounded relative to its unsigned contributions, Σ |q| / d over the other
|
|
55
|
+
bodies, not relative to its net force, which cancelling charges can make far
|
|
56
|
+
smaller than that error. `distanceMax` applies to each body: a cell straddling
|
|
57
|
+
it is opened. Differences, means, distances, the cutoff, the `distanceMin`
|
|
58
|
+
clamp and the force are scaled by powers of two wherever they, a square or the
|
|
59
|
+
clamp's product would underflow or overflow, cell centres are running means,
|
|
60
|
+
and positions beyond the quadtree's ±1e150 are indexed scaled, so any finite
|
|
61
|
+
coordinates and charges keep their force. Every force and the integration keep
|
|
62
|
+
positions and velocities finite for any finite inputs and options: one whose
|
|
63
|
+
exact value lies beyond the doubles saturates at ±`Number.MAX_VALUE`.
|
|
64
|
+
Collisions widen their pruning by how far any node
|
|
65
|
+
has moved in the pass (the skin of Verlet's neighbour lists), so a node pushed
|
|
66
|
+
into another's reach earlier in the same pass is still caught; the active
|
|
67
|
+
node's own prediction is refreshed after each push and its walk repeated on it,
|
|
68
|
+
so its later pairs are tested where it now stands. A self-link exerts no force.
|
|
69
|
+
|
|
70
|
+
`compatibility: "d3-force"` reproduces d3-force 3 to rounding instead, quirks
|
|
71
|
+
included: with the same random source, Barnes–Hut mode then matches d3-force's
|
|
72
|
+
own Barnes–Hut (same θ) and `"exact"` mode matches d3-force with θ = 0. A
|
|
73
|
+
pinned axis keeps its pin even when the node has no initial position (d3-force
|
|
74
|
+
would replace it with the phyllotaxis coordinate until the first tick).
|
|
62
75
|
|
|
63
76
|
```ts
|
|
64
77
|
import { forceDirectedLayout, createForceStep } from "@ac-kit/math-graph";
|
|
@@ -89,5 +102,18 @@ step(positions, velocities, 0.3);
|
|
|
89
102
|
`forceDirectedLayoutAsync` takes `signal` and `sliceMs`, yields between steps
|
|
90
103
|
and returns the same result.
|
|
91
104
|
|
|
105
|
+
## Layered layout
|
|
106
|
+
|
|
107
|
+
`layeredLayout` reduces crossings with barycentre and median sweeps (Sugiyama,
|
|
108
|
+
Tagawa and Toda 1981; Eades and Wormald 1994) and adjacent transpositions
|
|
109
|
+
(Gansner et al. 1993) from two depth-first starting orders. With
|
|
110
|
+
`orderingEffort: "thorough"`, the default, it then sifts (Matuszewski,
|
|
111
|
+
Schönfeld and Molitor 1999): each vertex in turn moves to the slot of its layer
|
|
112
|
+
with the fewest crossings, which leaves the local minima the sweeps stop in, at
|
|
113
|
+
O(k · e) per round and layer of k vertices and e segments. `"fast"` stops after
|
|
114
|
+
the sweeps. Either effort returns the fewest-crossing order it saw, and
|
|
115
|
+
`"thorough"` never has more crossings than `"fast"`. `sankeyLayout`'s
|
|
116
|
+
`ordering: "crossings"` takes the same `orderingEffort`.
|
|
117
|
+
|
|
92
118
|
See the [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/math-graph/)
|
|
93
119
|
for the full reference.
|
|
@@ -10,7 +10,11 @@ export type LinkForceData = {
|
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Springs between linked nodes, on positions advanced by their velocities (the
|
|
13
|
-
* velocity-Verlet predictor); the correction goes to the velocities.
|
|
13
|
+
* velocity-Verlet predictor); the correction goes to the velocities. A link
|
|
14
|
+
* whose squared length, ratio `(l − d) / l` or move would leave the doubles is
|
|
15
|
+
* settled on lengths scaled by a power of two, each end's share applied before
|
|
16
|
+
* scaling back, so that it pulls or pushes wherever its share of the move is
|
|
17
|
+
* finite (a rest length of `Number.MAX_VALUE` included).
|
|
14
18
|
*/
|
|
15
19
|
export declare function applyLinkForce(positions: Float64Array, velocities: Float64Array, alpha: number, data: LinkForceData, random: RandomFn): void;
|
|
16
20
|
export type ManyBodyOptions = {
|
|
@@ -19,32 +23,90 @@ export type ManyBodyOptions = {
|
|
|
19
23
|
readonly distanceMin: number;
|
|
20
24
|
readonly distanceMax: number;
|
|
21
25
|
readonly random: RandomFn;
|
|
26
|
+
/** D3-force's Barnes–Hut criterion and its quirks (`compatibility`). */
|
|
27
|
+
readonly isD3: boolean;
|
|
22
28
|
};
|
|
23
29
|
/**
|
|
24
|
-
* Charges repelling or attracting each other with strength / distance
|
|
25
|
-
* Barnes–Hut (Barnes and Hut,
|
|
26
|
-
*
|
|
27
|
-
*
|
|
30
|
+
* Charges repelling or attracting each other with strength / distance, every
|
|
31
|
+
* pair in `"exact"` mode or Barnes–Hut (Barnes and Hut, "A hierarchical O(N log
|
|
32
|
+
* N) force-calculation algorithm", Nature 324, 1986) over a `Quadtree`.
|
|
33
|
+
*
|
|
34
|
+
* Each cell keeps two monopoles: the sum of its positive charges at their
|
|
35
|
+
* centre, and the sum of its negative charges at theirs. A cell is summarised
|
|
36
|
+
* only when each of its monopoles looks small enough from the node (width / θ <
|
|
37
|
+
* the distance to that monopole's centre, d3-force's form of the criterion), so
|
|
38
|
+
* each monopole's error is bounded relative to its own charge over its
|
|
39
|
+
* distance, as for same-sign charges, and a cell is never skipped because its
|
|
40
|
+
* charges sum to 0. The error of a node's force is therefore bounded relative
|
|
41
|
+
* to its unsigned contributions, Σ |q_j| / d_j over the other bodies, not
|
|
42
|
+
* relative to the net force: where contributions of opposite signs cancel, the
|
|
43
|
+
* net force can be any number of times smaller than that error. A cell is
|
|
44
|
+
* always opened when the node lies inside it, enlarged by 20 % (Springel, "The
|
|
45
|
+
* cosmological simulation code GADGET-2", MNRAS 364, 2005, §3.1), so no node
|
|
46
|
+
* feels its own charge however large θ is: the self-interaction that Salmon and
|
|
47
|
+
* Warren ("Skeletons from the treecode closet", J. Comput. Phys. 111, 1994)
|
|
48
|
+
* show unbounds the error of the plain criterion. A cell that straddles
|
|
49
|
+
* `distanceMax` is opened too, so the cutoff applies to each body, as in
|
|
50
|
+
* `"exact"` mode. Centres are running charge-weighted means (a convex
|
|
51
|
+
* combination where a step would overflow), differences beyond the doubles are
|
|
52
|
+
* taken from halves, distances, the cutoff, the clamp and the force are scaled
|
|
53
|
+
* by powers of two wherever a square would underflow or overflow, a cell's
|
|
54
|
+
* charge sums by the power of two that keeps the total of every |charge|
|
|
55
|
+
* finite, and positions beyond the quadtree's ±1e150 are indexed scaled by a
|
|
56
|
+
* power of two (the cells scaled back), so any finite coordinates, distances
|
|
57
|
+
* down to the least subnormal and charges up to the double range keep their
|
|
58
|
+
* force; a velocity beyond the doubles saturates at ±`Number.MAX_VALUE`.
|
|
59
|
+
*
|
|
60
|
+
* `isD3` keeps d3-force's own approximation instead: one signed monopole at the
|
|
61
|
+
* |charge|-weighted centre, a cell summarised even when it holds the node,
|
|
62
|
+
* `distanceMax` tested against the cell's centre, cells whose charges sum to 0
|
|
63
|
+
* skipped, and coincident offsets drawn whenever one axis difference is 0.
|
|
28
64
|
*/
|
|
29
65
|
export declare class ManyBodyForce {
|
|
30
66
|
private readonly charges;
|
|
31
67
|
private readonly options;
|
|
32
68
|
private readonly tree;
|
|
69
|
+
/** Positive charge of each cell (its signed sum when `isD3`). */
|
|
33
70
|
private values;
|
|
34
71
|
private centersX;
|
|
35
72
|
private centersY;
|
|
73
|
+
/** Negative charge of each cell (unused when `isD3`). */
|
|
74
|
+
private negativeValues;
|
|
75
|
+
private negativeCentersX;
|
|
76
|
+
private negativeCentersY;
|
|
36
77
|
private readonly scratch;
|
|
37
78
|
private positions;
|
|
38
79
|
private velocities;
|
|
39
80
|
private readonly order;
|
|
40
81
|
private orderLength;
|
|
41
82
|
private readonly isExact;
|
|
83
|
+
private readonly isD3;
|
|
42
84
|
private readonly isInert;
|
|
43
85
|
private readonly theta2;
|
|
44
86
|
private readonly distanceMin2;
|
|
45
87
|
private readonly distanceMax2;
|
|
88
|
+
/**
|
|
89
|
+
* The charges a cell sums, scaled down by `monopoleScale`, a power of two
|
|
90
|
+
* from 1 up: so far that the sum of every |charge| stays finite, and no
|
|
91
|
+
* further, so a charge loses no digit unless it is subnormal already.
|
|
92
|
+
*/
|
|
93
|
+
private readonly scaledCharges;
|
|
94
|
+
private readonly monopoleScale;
|
|
95
|
+
/**
|
|
96
|
+
* Positions scaled into the quadtree's range when one lies beyond it (grown,
|
|
97
|
+
* then reused), and the power of two the tree's cells are to be multiplied
|
|
98
|
+
* by: 1 while the positions are indexed as they are.
|
|
99
|
+
*/
|
|
100
|
+
private treePositions;
|
|
101
|
+
private cellScale;
|
|
46
102
|
constructor(charges: Float64Array, options: ManyBodyOptions);
|
|
47
103
|
apply(positions: Float64Array, velocities: Float64Array, alpha: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Indexes the positions, scaled by a power of two into the quadtree's range
|
|
106
|
+
* where one lies beyond it: the cells are then `cellScale` times the tree's,
|
|
107
|
+
* and every force still reads the positions themselves.
|
|
108
|
+
*/
|
|
109
|
+
private assignTree;
|
|
48
110
|
/**
|
|
49
111
|
* Every pair, the others taken in the tree's leaf order: the order the
|
|
50
112
|
* Barnes–Hut walk sums them in, so exact and approximate runs differ only by
|
|
@@ -52,39 +114,100 @@ export declare class ManyBodyForce {
|
|
|
52
114
|
*/
|
|
53
115
|
private applyExact;
|
|
54
116
|
private readonly collectLeaves;
|
|
55
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* `isD3`: signed charge and |charge|-weighted centre of every cell, children
|
|
119
|
+
* first.
|
|
120
|
+
*/
|
|
121
|
+
private readonly accumulateD3;
|
|
122
|
+
/**
|
|
123
|
+
* Positive and negative charge of every cell, scaled down by `monopoleScale`,
|
|
124
|
+
* each at its own charge-weighted centre, children first. A sign with no
|
|
125
|
+
* charge has its centre at the origin; it is never read.
|
|
126
|
+
*/
|
|
56
127
|
private readonly accumulate;
|
|
128
|
+
/**
|
|
129
|
+
* The Barnes–Hut walk for the node in `scratch`: a cell is summarised by its
|
|
130
|
+
* two monopoles, opened, or skipped whole (no charge, or every body beyond
|
|
131
|
+
* `distanceMax`); a leaf is summed body by body.
|
|
132
|
+
*/
|
|
57
133
|
private readonly visit;
|
|
134
|
+
/**
|
|
135
|
+
* Every body of the leaf `node` but the node in `scratch`, as `"exact"` sums
|
|
136
|
+
* them: the cutoff per body, coincident bodies parted by a jiggle.
|
|
137
|
+
*/
|
|
138
|
+
private applyLeaf;
|
|
139
|
+
/** `isD3`: d3-force's walk, quirks included (see the class). */
|
|
140
|
+
private readonly visitD3;
|
|
141
|
+
/**
|
|
142
|
+
* {@link visitD3} for a cell whose centre is so far from the node that the
|
|
143
|
+
* difference leaves the doubles (taken from halves in `PAIR_`): d3-force's
|
|
144
|
+
* tests on scaled lengths, and the force from `addPull_`. No offset is drawn,
|
|
145
|
+
* as the two cannot coincide.
|
|
146
|
+
*/
|
|
147
|
+
private visitD3Wide;
|
|
58
148
|
}
|
|
59
149
|
/**
|
|
60
150
|
* Pushes overlapping discs apart, nodes tested on their predicted positions
|
|
61
151
|
* (position + velocity). The tree prunes cells by their largest radius, so the
|
|
62
|
-
* result is exact whatever the many-body approximation.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
152
|
+
* result is exact whatever the many-body approximation. The pruning is widened
|
|
153
|
+
* by how far any prediction has moved since the pass started (the "skin" of
|
|
154
|
+
* Verlet's neighbour lists: Verlet, Phys. Rev. 159, 1967), so a node pushed
|
|
155
|
+
* into another's reach by an earlier pair of the same pass is still tested, and
|
|
156
|
+
* every pair of a chain of coincident nodes collides. The active node's own
|
|
157
|
+
* prediction is refreshed after each push, and its walk repeated on the moved
|
|
158
|
+
* prediction (skipping the pairs already pushed) until a walk pushes none, so
|
|
159
|
+
* no later pair is tested on where it no longer stands. Where a squared radius,
|
|
160
|
+
* reach or distance would overflow or underflow, the pair is settled on lengths
|
|
161
|
+
* scaled by a power of two and the shares on the ratio of the radii, each
|
|
162
|
+
* node's share applied before scaling back, so any finite radii and distances
|
|
163
|
+
* push (radii of `Number.MAX_VALUE` included) and only a node's part of a
|
|
164
|
+
* displacement beyond the doubles overflows.
|
|
165
|
+
*
|
|
166
|
+
* `isD3` keeps d3-force's behaviour instead: cells bounded on the predictions
|
|
167
|
+
* made when the pass starts, so such a pair is missed until the next pass, and
|
|
168
|
+
* only the newest node of a coincident chain tested (and its radius taken as
|
|
169
|
+
* the leaf's).
|
|
67
170
|
*/
|
|
68
171
|
export declare class CollideForce {
|
|
69
172
|
private readonly radii;
|
|
70
173
|
private readonly strength;
|
|
71
174
|
private readonly iterations;
|
|
72
175
|
private readonly random;
|
|
73
|
-
private readonly
|
|
176
|
+
private readonly isD3;
|
|
74
177
|
private readonly tree;
|
|
75
178
|
private readonly predicted;
|
|
179
|
+
/**
|
|
180
|
+
* Per node, the walk (`scratch[7]`) that last pushed it against the active
|
|
181
|
+
* node.
|
|
182
|
+
*/
|
|
183
|
+
private readonly pushedIn;
|
|
76
184
|
private cellRadii;
|
|
77
185
|
private readonly scratch;
|
|
78
186
|
private positions;
|
|
79
187
|
private velocities;
|
|
80
|
-
|
|
188
|
+
/** The power of two the tree's cells are to be multiplied by. */
|
|
189
|
+
private cellScale;
|
|
190
|
+
constructor(radii: Float64Array, strength: number, iterations: number, random: RandomFn, isD3: boolean);
|
|
81
191
|
apply(positions: Float64Array, velocities: Float64Array): void;
|
|
82
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* Indexes the predictions `position + velocity`, scaled by a power of two
|
|
194
|
+
* into the quadtree's range where one lies beyond it (or beyond the doubles):
|
|
195
|
+
* the cells are then `cellScale` times the tree's.
|
|
196
|
+
*/
|
|
197
|
+
private assignTree;
|
|
198
|
+
/**
|
|
199
|
+
* Writes the node's prediction into `scratch[0]` and `scratch[1]`, for the
|
|
200
|
+
* pruning test: saturated at ±`Number.MAX_VALUE` beyond the doubles, which
|
|
201
|
+
* only prunes less.
|
|
202
|
+
*/
|
|
203
|
+
private notePrediction;
|
|
204
|
+
/** Largest radius under every cell (`isD3`: a leaf's newest node's). */
|
|
83
205
|
private readonly prepare;
|
|
84
206
|
private readonly visit;
|
|
85
207
|
/**
|
|
86
208
|
* Cells were bounded on the predictions made at the start of the pass; the
|
|
87
|
-
* pruning test widens them by how far any prediction has moved since
|
|
209
|
+
* pruning test widens them by how far any prediction has moved since (in the
|
|
210
|
+
* tree's units, scaled back: beyond the doubles it only prunes less).
|
|
88
211
|
*/
|
|
89
212
|
private noteShift;
|
|
90
213
|
}
|
|
@@ -97,7 +220,8 @@ export declare function applyGravity(positions: Float64Array, velocities: Float6
|
|
|
97
220
|
export declare function applyCentering(positions: Float64Array, strength: number, centerX: number, centerY: number): void;
|
|
98
221
|
/**
|
|
99
222
|
* Velocity Verlet: v ← v · keep, x ← x + v; a pinned axis (finite entry of
|
|
100
|
-
* `fixedPositions`) is set to its pin with zero velocity.
|
|
223
|
+
* `fixedPositions`) is set to its pin with zero velocity. A position beyond the
|
|
224
|
+
* doubles saturates at ±`Number.MAX_VALUE`.
|
|
101
225
|
*/
|
|
102
226
|
export declare function integrate(positions: Float64Array, velocities: Float64Array, keep: number, fixedPositions: Float64Array | undefined): void;
|
|
103
227
|
//# sourceMappingURL=_force-forces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_force-forces.d.ts","sourceRoot":"","sources":["../../src/layout/_force-forces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version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