Constructor
new SpatialHashGrid(configopt)
| Name | Type | Attributes | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config | Object | <optional> | Properties
|
- Source
Classes
Members
size
Get the count of tracked entries.
Methods
clear()
Clear all cells and entries (e.g. on scene unload).
getCellKeysForBounds(bounds) → {Set.<string>}
Compute set of cell keys covered by an AABB. Handles negative cells and clamps huge colliders to maxCellSpan.
| Name | Type | Description |
|---|---|---|
bounds | Object | { left, right, top, bottom } |
- Source
- Type:
- Set.<string>
getPotentialCollisionPairs() → {Array.<Array>}
Generate unique potential collision pairs across all cells. Returns an array of [entryA, entryB] pairs with deterministic ordering.
- Type:
- Array.<Array>
insert(entry, bounds)
Insert an entry into the spatial grid.
| Name | Type | Description |
|---|---|---|
entry | Object | Object identifier (collider, entity, etc.) |
bounds | Object | { left, right, top, bottom } |
- Source
queryAABB(bounds) → {Array.<Object>}
Query all unique entries whose bounding box overlaps the given AABB.
| Name | Type | Description |
|---|---|---|
bounds | Object | { left, right, top, bottom } |
- Type:
- Array.<Object>
queryRadius(x, y, radius) → {Array.<Object>}
Query all unique entries within a circular radius of a point.
| Name | Type | Description |
|---|---|---|
x | number | Center X |
y | number | Center Y |
radius | number | Search radius |
- Type:
- Array.<Object>
remove(entry) → {boolean}
Remove an entry from all cells.
| Name | Type | Description |
|---|---|---|
entry | Object |
Whether entry was present and removed
- Type:
- boolean
teleport(entry, newBounds)
Teleport an entry instantly to new bounds.
| Name | Type | Description |
|---|---|---|
entry | Object | |
newBounds | Object |
update(entry, newBounds) → {boolean}
Update an entry's position and bounding box. If the cell coverage did not change, avoids bucket re-insertions.
| Name | Type | Description |
|---|---|---|
entry | Object | |
newBounds | Object |
Whether spatial bucket assignment changed
- Type:
- boolean
worldToCell(coord) → {number}
Convert world coordinate to cell coordinate index. Uses Math.floor to correctly handle negative coordinates.
| Name | Type | Description |
|---|---|---|
coord | number |
- Source
- Type:
- number