• Create a quadtree for a given area.

    Type Parameters

    • T extends object

      The type of children of this quadtree contains.

    Parameters

    Returns Quadtree<T>

    interface Rectangle {
    x: number;
    y: number;
    width: number;
    height: number;
    }

    const rectBounds = ({ x, y, width, height }: Rectangle) =>
    [x, y, x + width, r.y + height];

    const qt = quadtree<Rectangle>([0,0,1000,1000], rectBounds);

    // Add a rectangle
    qt.insert({ x: 20, y: 20, width: 50, height: 50 });

    // Collect items
    const results = qt.collect([0, 0, 100, 100]);
    const qt = quadtree<Rectangle>(
    [0,0,1000,1000],
    rectBounds,
    {
    maxDepth: 4,
    maxChildren: 50
    }
    );
    const qt = quadtree<DOMRect>(
    [0, 0, 1000, 1000],
    ({ left, top, right, bottom }) => [left, top, right, bottom],
    );