A Quadtree implementation
Types
Bounds* = concept b b.y is int b.x is int b.width is int b.height is int
- The position and dimensions of a bounding box
Square* = tuple[y, x, size: int]
- A square on a grid
QuadableBare* = concept q q.y is int q.x is int q.width is int q.height is int `==`(q, q) is bool
- An element that can be stored in a quadtree
QuadableContains* = concept q contains(Square, q) is bool q.y is int q.x is int q.width is int q.height is int `==`(q, q) is bool
- An element that can be stored in a quadtree
QuadableBounds* = concept q boundingBox(q) is Bounds `==`(q, q) is bool
- An element that can be stored in a quadtree
QuadableFull* = concept q boundingBox(q) is Bounds contains(Square, q) is bool `==`(q, q) is bool
- An element that can be stored in a quadtree
Quadable* = QuadableBare | QuadableBounds | QuadableContains | QuadableFull
- An element that can be stored in a quadtree. It can take multiple forms, depending on the level of control desired
Procs
proc newQuadtree*[E: Quadable](maxInQuadrant: int = 2): Quadtree[E]
- Creates a new quadtree
proc `$`*[E: Quadable](tree: Quadtree[E]): string
- Convert a Quadtree to a string
proc bounds*[E: Quadable](tree: Quadtree[E]): Option[Square]
- Returns the overall bounding box for a tree. This will be 'none' if this tree doesn't have any content
proc insert*[E: Quadable](tree: var Quadtree[E]; elem: E)
- Adds a new element to a quadtree
proc fetch*[E: Quadable](tree: Quadtree[E]; x, y: int): seq[E]
- Returns the elements at the given coordinate
proc delete*[E: Quadable](tree: var Quadtree[E]; elem: E)
- Removes the given element from this quadtree