Skip to content
mbostock edited this page Dec 24, 2012 · 26 revisions

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(point, [x1, y1, x2, y2])

Constructs a new quadtree for the specified array of points.

# 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.

Clone this wiki locally