Interface Quadtree<T>

interface Quadtree {
    add(datum): Quadtree<T>;
    addAll(data): Quadtree<T>;
    copy(): Quadtree<T>;
    cover(x, y): Quadtree<T>;
    data(): T[];
    extent(): [[number, number], [number, number]];
    extent(extend): Quadtree<T>;
    find(x, y, radius?): T;
    remove(datum): Quadtree<T>;
    removeAll(data): Quadtree<T>;
    root(): QuadtreeInternalNode<T> | QuadtreeLeaf<T>;
    size(): number;
    visit(callback): Quadtree<T>;
    visitAfter(callback): Quadtree<T>;
    x(): ((d) => number);
    x(x): Quadtree<T>;
    y(): ((d) => number);
    y(y): Quadtree<T>;
}

Type Parameters

  • T

Methods

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

    Parameters

    • datum: T

      The specified datum to add.

    Returns Quadtree<T>

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

    Parameters

    • data: T[]

      The specified array of data to add.

    Returns Quadtree<T>

  • Returns a copy of the quadtree. All nodes in the returned quadtree are identical copies of the corresponding node in the quadtree; however, any data in the quadtree is shared by reference and not copied.

    Returns Quadtree<T>

  • Expands the quadtree to cover the specified point ⟨x,y⟩, and returns the quadtree.

    • If the quadtree’s extent already covers the specified point, this method does nothing.
    • If the quadtree has an extent, the extent is repeatedly doubled to cover the specified point, wrapping the root node as necessary.
    • If the quadtree is empty, the extent is initialized to the extent [[⌊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.

    Parameters

    • x: number

      The x-coordinate for the specified point to cover.

    • y: number

      The y-coordinate for the specified point to cover.

    Returns Quadtree<T>

  • Returns an array of all data in the quadtree.

    Returns T[]

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

    Returns [[number, number], [number, number]]

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

    Parameters

    • extend: [[number, number], [number, number]]

      The specified points to cover.

    Returns Quadtree<T>

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

    Parameters

    • x: number

      The x-coordinate for the search position.

    • y: number

      The y-coordinate for the search position.

    • Optional radius: number

      The optional search radius.

    Returns T

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

    Parameters

    • datum: T

      The specified datum to remove.

    Returns Quadtree<T>

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

    Parameters

    • data: T[]

      The specified array of data to remove.

    Returns Quadtree<T>

  • Returns the total number of data in the quadtree.

    Returns number

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

    Parameters

    • callback: ((node, x0, y0, x1, y1) => boolean | void)

      The callback invoked for each node.

    Returns Quadtree<T>

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

    Parameters

    • callback: ((node, x0, y0, x1, y1) => void)

      The callback invoked for each node.

    Returns Quadtree<T>

  • Returns the current x-accessor, which defaults to: x(d) => d[0].

    Returns ((d) => number)

      • (d): number
      • Returns the current x-accessor, which defaults to: x(d) => d[0].

        Parameters

        • d: T

        Returns number

  • Sets the current x-coordinate accessor and returns the quadtree. The x-accessors must be consistent, returning the same value given the same input.

    Parameters

    • x: ((d) => number)

      The x-coordinate accessor.

        • (d): number
        • Parameters

          • d: T

          Returns number

    Returns Quadtree<T>

  • Returns the current y-accessor, which defaults to: y(d) => d[1].

    Returns ((d) => number)

      • (d): number
      • Returns the current y-accessor, which defaults to: y(d) => d[1].

        Parameters

        • d: T

        Returns number

  • Sets the current y-coordinate accessor and returns the quadtree. The y-accessors must be consistent, returning the same value given the same input.

    Parameters

    • y: ((d) => number)

      The y-coordinate accessor.

        • (d): number
        • Parameters

          • d: T

          Returns number

    Returns Quadtree<T>