/** * Barnes-Hut octree for n-body repulsion. * * @description * Every node in a force layout repels every other one, which is O(n²): at five * thousand nodes that is twenty-five million pairs per tick, and the layout * simply stops running. Barnes-Hut groups distant nodes into their centre of * mass and treats each group as one body, bringing a tick to O(n log n). * * `theta` is the accuracy dial: a cell is treated as a single body when its * width divided by the distance to it is below `theta`. Zero is exact and slow; * larger values are faster and coarser. 0.8 is the usual compromise and is what * makes thousands of nodes interactive. */ export interface OctreeBody { x: number; y: number; z: number; /** Repulsion weight. Defaults to 1 per body. */ mass?: number; } export declare class Octree { private root; constructor(bodies: OctreeBody[]); private insert; /** * Accumulates the repulsion acting on one body. * * @param strength - Coulomb constant. Negative values attract. * @param theta - Accuracy dial; see the module description. * @param out - Mutated in place, so a tick allocates nothing per body. */ accumulate(body: OctreeBody, strength: number, theta: number, out: { fx: number; fy: number; fz: number; }, /** * Floor on the separation used in the inverse-square term. * * Without it, two nearly coincident nodes divide by an almost-zero distance * and produce a force large enough to fling the whole graph to infinity on * the first tick. This is the single most important guard in the layout. */ minDistance?: number): void; private walk; }