Quadtree Geom - zziuni/d3 GitHub Wiki

WikiGeometryQuadtree Geom

A quadtree is a two-dimensional recursive spatial subdivision. This implementation uses square partitions, dividing each square into four equally-sized squares. Each point exists in a unique node; if multiple points are in the same position, some points may be stored on internal nodes rather than leaf nodes. Quadtrees can be used to accelerate various spatial operations, such as the Barnes-Hut approximation for computing n-body forces, or collision detection.

# d3.geom.quadtree(points, [x1, y1, x2, y2 | width, height])

Constructs a new quadtree for the specified array of points. Bounds are optional and can be specified explicitly as x1, y1, x2, y2, or as width, height, which is equivalent to 0, width, 0, height.

# quadtree.add(point)

Adds a new point to the quadtree.

# quadtree.visit(callback)

The specified callback is invoked with the arguments (node, x1, y1, x2, y2) for each quadtree node pre-order, provided the callback returns false. If callback returns true for a node, then the children of that node are not visited.

⚠️ **GitHub.com Fallback** ⚠️