HashGrid3D
Defined in: src/modules/spatial/hash-grid-3d.ts:36
Spatial hash over continuous {x, y, z} positions. Implements
SpatialStructure with TPos = {x, y, z}, so it plugs into
world.enableSpatial(Position3DDef, new HashGrid3D({ cellSize })).
Each position is bucketed into the cubic cell floor(p / cellSize) on every
axis. The grid keeps a copy of each entity’s position, so:
queryNearandqueryRectare exact — Euclidean distance and inclusive bounds against the stored position, not just “shares a cell”;removeandmovefind the entity’s current cell from the stored copy.
An entity holds one position: add on an entity already present moves it.
queryAt(pos) returns the entities in the cell containing pos.
Pick cellSize near the typical query radius: much smaller and a query
walks many empty cells, much larger and each cell holds many candidates.
A query whose box spans more cells than the grid holds entities scans the
stored positions instead.
Implements
Section titled “Implements”SpatialStructure<Pos3>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new HashGrid3D(
options?):HashGrid3D
Defined in: src/modules/spatial/hash-grid-3d.ts:41
Parameters
Section titled “Parameters”options?
Section titled “options?”HashGrid3DOptions = {}
Returns
Section titled “Returns”HashGrid3D
Properties
Section titled “Properties”cellSize
Section titled “cellSize”
readonlycellSize:number
Defined in: src/modules/spatial/hash-grid-3d.ts:38
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/modules/spatial/hash-grid-3d.ts:177
Number of entities in the grid.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(
id,pos):void
Defined in: src/modules/spatial/hash-grid-3d.ts:48
Register an entity at a position. No-op if already present at that position.
Parameters
Section titled “Parameters”Pos3
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear():
void
Defined in: src/modules/spatial/hash-grid-3d.ts:97
Remove all entries.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”has(
id):boolean
Defined in: src/modules/spatial/hash-grid-3d.ts:103
Whether id is in the grid.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
move()
Section titled “move()”move(
id,_from,to):void
Defined in: src/modules/spatial/hash-grid-3d.ts:130
Move id to to. The stored position, not from, locates its current cell. Adds id if absent.
Parameters
Section titled “Parameters”Pos3
Pos3
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”positionOf()
Section titled “positionOf()”positionOf(
id):Pos3|undefined
Defined in: src/modules/spatial/hash-grid-3d.ts:135
The position id was last added or moved to, or undefined if absent.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Pos3 | undefined
queryAt()
Section titled “queryAt()”queryAt(
pos):Iterable<EntityId>
Defined in: src/modules/spatial/hash-grid-3d.ts:139
All entity IDs at pos. Empty iterable if none.
Parameters
Section titled “Parameters”Pos3
Returns
Section titled “Returns”Iterable<EntityId>
Implementation of
Section titled “Implementation of”queryNear()
Section titled “queryNear()”queryNear(
pos,radius):Iterable<EntityId>
Defined in: src/modules/spatial/hash-grid-3d.ts:145
All entity IDs within radius of pos (Euclidean, inclusive).
radius is in the same units as the position coordinates.
Parameters
Section titled “Parameters”Pos3
radius
Section titled “radius”number
Returns
Section titled “Returns”Iterable<EntityId>
Implementation of
Section titled “Implementation of”queryRect()
Section titled “queryRect()”queryRect(
min,max):Iterable<EntityId>
Defined in: src/modules/spatial/hash-grid-3d.ts:159
All entity IDs within an axis-aligned region (inclusive bounds). min / max are the region corners.
Parameters
Section titled “Parameters”Pos3
Pos3
Returns
Section titled “Returns”Iterable<EntityId>
Implementation of
Section titled “Implementation of”remove()
Section titled “remove()”remove(
id,_pos?):void
Defined in: src/modules/spatial/hash-grid-3d.ts:168
Remove id. The stored position, not pos, locates its cell. No-op if absent.
Parameters
Section titled “Parameters”Pos3
Returns
Section titled “Returns”void