Collection Kit

QuadTree

Spatial

A QuadTree is a tree data structure that partitions a two-dimensional space into four quadrants or regions, allowing for efficient spatial indexing and querying.

Import Statement
import { QuadTree } from "collection-kit";

Key Features

  • Spatial Partitioning: Divides space into quadrants for efficient storage and retrieval.
  • Dynamic Size: Can grow and shrink as elements are added or removed.

Common Operations

Insert
Add a new point to the QuadTree.
Search
Retrieve points within a specified region.
Remove
Delete a point from the QuadTree.

Example Code

import { QuadTree } from "collection-kit";

const tree = new QuadTree(0, 0, 100, 100); // x, y, width, height
tree.insert({ x: 10, y: 20 });
tree.insert({ x: 50, y: 60 });

const points = tree.search(0, 0, 30, 30);
console.log("Points in region:", points);