Adds the specified array of data to the quadtree, deriving each element’s coordinates ⟨x,y⟩ using the current x- and y-accessors, and return this quadtree. This is approximately equivalent to calling quadtree.add repeatedly. However, this method results in a more compact quadtree because the extent of the data is computed first before adding the data.
The specified array of data to add.
Expands the quadtree to cover the specified point ⟨x,y⟩, and returns the quadtree.
[[⌊x⌋, ⌊y⌋], [⌈x⌉, ⌈y⌉]]
.
Rounding is necessary such that if the extent is later doubled, the boundaries of existing quadrants do not change due to floating point error.The x-coordinate for the specified point to cover.
The y-coordinate for the specified point to cover.
Returns the quadtree's current extent [[x0, y0], [x1, y1]]
,
where x0
and y0
are the inclusive lower bounds and x1
and y1
are the inclusive upper bounds,
or undefined
if the quadtree has no extent.
Expands the quadtree to cover the specified points [[x0, y0], [x1, y1]]
and returns the quadtree.
The extent may also be expanded by calling quadtree.cover
or quadtree.add
.
The specified points to cover.
Returns the datum closest to the position ⟨x,y⟩ with the given search radius. If radius is not specified, it defaults to infinity. If there is no datum within the search area, returns undefined.
The x-coordinate for the search position.
The y-coordinate for the search position.
Optional
radius: numberThe optional search radius.
Removes the specified datum to the quadtree, deriving its coordinates ⟨x,y⟩ using the current x- and y-accessors, and returns the quadtree. If the specified datum does not exist in this quadtree, this method does nothing.
The specified datum to remove.
Removes the specified data to the quadtree, deriving their coordinates ⟨x,y⟩ using the current x- and y-accessors, and returns the quadtree. If a specified datum does not exist in this quadtree, it is ignored.
The specified array of data to remove.
Returns the root node of the quadtree.
Visits each node in the quadtree in pre-order traversal, invoking the specified callback with arguments node
, x0
, y0
, x1
, y1
for each node,
where node
is the node being visited, ⟨x0, y0⟩ are the lower bounds of the node, and ⟨x1, y1⟩ are the upper bounds, and returns the quadtree.
If the callback returns true for a given node, then the children of that node are not visited; otherwise, all child nodes are visited. This can be used to quickly visit only parts of the tree. Note, however, that child quadrants are always visited in sibling order: top-left, top-right, bottom-left, bottom-right. In cases such as search, visiting siblings in a specific order may be faster.
The callback invoked for each node.
Visits each node in the quadtree in post-order traversal, invoking the specified callback with arguments node
, x0
, y0
, x1
, y1
for each node,
where node
is the node being visited, ⟨x0, y0⟩ are the lower bounds of the node, and ⟨x1, y1⟩ are the upper bounds, and returns the quadtree.
The callback invoked for each node.
Returns the current x-accessor, which defaults to: x(d) => d[0]
.
Returns the current x-accessor, which defaults to: x(d) => d[0]
.
Sets the current x-coordinate accessor and returns the quadtree. The x-accessors must be consistent, returning the same value given the same input.
The x-coordinate accessor.
Returns the current y-accessor, which defaults to: y(d) => d[1]
.
Returns the current y-accessor, which defaults to: y(d) => d[1]
.
Sets the current y-coordinate accessor and returns the quadtree. The y-accessors must be consistent, returning the same value given the same input.
The y-coordinate accessor.
Adds the specified datum to the quadtree, deriving its coordinates ⟨x,y⟩ using the current x- and y-accessors, and returns the quadtree. If the new point is outside the current extent of the quadtree, the quadtree is automatically expanded to cover the new point.