/** * Barnes-Hut QuadTree — Spatial indexing for O(n log n) force simulation * * Used by the topology dashboard to replace the naive O(n²) all-pairs * repulsion with Barnes-Hut approximation. Also provides viewport queries * for culling off-screen nodes. * * @module QuadTree * @version 1.0.0 */ /** A 2D point with an identifier */ export interface QTPoint { id: string; x: number; y: number; } /** Axis-aligned bounding box */ export interface QTBounds { x: number; y: number; halfW: number; halfH: number; } /** Statistics about a QuadTree region (for Barnes-Hut) */ export interface QTMass { /** Total number of points in this region */ count: number; /** Center of mass x */ cx: number; /** Center of mass y */ cy: number; } /** * A QuadTree for 2D spatial indexing with Barnes-Hut mass summaries. * * Usage: * ```typescript * const qt = new QuadTree({ x: 500, y: 400, halfW: 500, halfH: 400 }); * qt.insert({ id: 'a', x: 100, y: 200 }); * qt.insert({ id: 'b', x: 300, y: 150 }); * * // Barnes-Hut force query (theta = 0.5) * qt.forceOnPoint(100, 200, 0.5, (cx, cy, mass, dx, dy, distSq) => { * // Apply repulsion force from (cx, cy) with given mass * }); * * // Viewport query * const visible = qt.queryRange({ x: 250, y: 250, halfW: 250, halfH: 250 }); * ``` */ export declare class QuadTree { private bounds; private points; private divided; private nw; private ne; private sw; private se; private mass; constructor(bounds: QTBounds); /** * Insert a point into the tree. * @returns true if inserted, false if out of bounds */ insert(point: QTPoint): boolean; /** * Build the tree from an array of points (faster than individual inserts). */ static build(points: QTPoint[], bounds: QTBounds): QuadTree; /** * Find all points within a rectangular viewport. */ queryRange(range: QTBounds): QTPoint[]; private queryRangeInto; /** * Traverse the tree with Barnes-Hut approximation for a single point. * * For each region, if the region is "far enough" (width/distance < theta), * treat it as a point mass at the center of mass. Otherwise recurse. * * @param px - Query point x * @param py - Query point y * @param theta - Opening angle threshold (0.5 is common, higher = faster but less accurate) * @param callback - Called for each mass interaction: (cx, cy, mass, dx, dy, distSq) */ forceOnPoint(px: number, py: number, theta: number, callback: (cx: number, cy: number, mass: number, dx: number, dy: number, distSq: number) => void): void; /** Total point count in this subtree */ get count(): number; /** The mass summary of this subtree */ getMass(): QTMass; /** The bounds of this node */ getBounds(): QTBounds; /** Whether this node has been subdivided */ get isSubdivided(): boolean; /** * Get cluster summaries at a given depth or size threshold. * Returns groups of points that share a QuadTree cell below the given size. * * @param maxCellSize - Maximum cell width to stop recursing (in world units) * @returns Array of clusters, each with center, count, and contained point ids */ getClusters(maxCellSize: number): Array<{ cx: number; cy: number; count: number; ids: string[]; }>; private collectClusters; private collectAllIds; private subdivide; private containsPoint; private intersects; } //# sourceMappingURL=quadtree.d.ts.map