A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries.
An easy way to use this within a browser is to use the built-in DOMRect class, consider:
import { quadtree, type Bounds } from '@4bitlabs/quadtree';const rectBounds = (r: DOMRect) => [r.left, r.top, r.right, r.bottom];const space = quadtree<DOMRect>([0, 0, 1000, 1000], rectBounds);space.insert(new DOMRect(25, 25, 50, 50));const matches = space.search([20, 20, 80, 80]); Copy
import { quadtree, type Bounds } from '@4bitlabs/quadtree';const rectBounds = (r: DOMRect) => [r.left, r.top, r.right, r.bottom];const space = quadtree<DOMRect>([0, 0, 1000, 1000], rectBounds);space.insert(new DOMRect(25, 25, 50, 50));const matches = space.search([20, 20, 80, 80]);
quadtree
A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries.
Example
An easy way to use this within a browser is to use the built-in DOMRect class, consider:
See
quadtree