Spacial index that allows for querying of objects within a radius of a given point
Details about the specific sof this algorithm can be found here:
https://elephantstarballoon.com/post/ahgrid/
Example:
import src/ahgrid var grid = newAHGrid[tuple[x, y, width, height: int32]]() discard grid.insert((x: 1'i32, y: 2'i32, width: 3'i32, height: 4'i32)) discard grid.insert((x: 5'i32, y: 6'i32, width: 7'i32, height: 8'i32)) for obj in grid.find(3, 4, 10): echo "Found object near point: ", obj
Types
AHGrid[T] = ref object
- A 2d spacial index
GridHandle[T] = object
- A handle for a value that can be stored in a AHGrid -- used to update that value
SpatialObject = concept obj obj.x is int32 obj.y is int32 obj.width is int32 obj.height is int32
- A value that can be stored in a 2d AHGrid
Procs
proc hash(x: CellIndex): Hash {....raises: [], tags: [], forbids: [].}
proc insert[T: SpatialObject](grid: var AHGrid[T]; value: T): GridHandle[T] {. inline.}
- Add a value to this spacial grid
proc insert[T](grid: var AHGrid[T]; value: T; space: SpatialObject): GridHandle[ T]
- Add a value to this spacial grid
proc remove[T](grid: var AHGrid[T]; handle: GridHandle[T])
proc update[T: SpatialObject](handle: var GridHandle[T]) {.inline.}
- Updates the spatial indexing for an object
proc update[T](handle: var GridHandle[T]; space: SpatialObject)
- Updates the spatial indexing for an object using the specified spatial information