Home /Modules/spatial/SLSpatialHash.md

SLSpatialHash.md

lib/spatial/SLSpatialHash.md · 35 line(s) · markdown

SLSpatialHash

SLSpatialHash is a sparse 3D spatial hash grid. Continuous integer points are quantized to cells of a fixed cellSize, and each occupied cell maps to a String payload (an id or label). Cells are distributed across a fixed number of hash buckets with per-bucket chains, so insert and point lookup are near O(1), and a "what is near P" scan only visits the cells of the neighbourhood around P rather than the whole populated set. Suited to sparse worlds, point clouds, and broad-phase collision.

Negative coordinates are handled with floor division (point -1 with cellSize 10 is in cell -1, not 0) and a non-negative bucket index.

Operations

A cell holds at most one payload; inserting into an occupied cell overwrites it.

Example

See SLSpatialHashBasic.