SpatialStructure
Defined in: src/spatial-structure.ts:18
Generic spatial index contract. Every spatial backend — hash-grid,
quadtree, octree, R-tree, BVH, brute-force — implements this minimum
surface. TPos is the position shape: {x, y} for 2D, {x, y, z} for
3D, {min, max} for AABBs, etc.
Query methods return Iterable<EntityId> (never Set or Array) so
lazy backends can yield without materializing intermediate collections.
Consumers that need Set semantics call new Set(queryAt(pos))
explicitly. Grid-specific extras like HashGrid2D.getAt (which returns
ReadonlySet | undefined directly) live on the implementation, not the
interface contract.
@pierre/ecs/modules/spatial for the shipped HashGrid2D impl.
Type Parameters
Section titled “Type Parameters”TPos
Properties
Section titled “Properties”add: (
id,pos) =>void
Defined in: src/spatial-structure.ts:20
Register an entity at a position. No-op if already present at that position.
Parameters
Section titled “Parameters”TPos
Returns
Section titled “Returns”void
clear: () =>
void
Defined in: src/spatial-structure.ts:23
Remove all entries.
Returns
Section titled “Returns”void
move: (
id,from,to) =>void
Defined in: src/spatial-structure.ts:26
Move an entity from one position to another. Equivalent to remove+add but may skip work when positions are equivalent.
Parameters
Section titled “Parameters”TPos
TPos
Returns
Section titled “Returns”void
queryAt
Section titled “queryAt”queryAt: (
pos) =>Iterable<EntityId>
Defined in: src/spatial-structure.ts:29
All entity IDs at pos. Empty iterable if none.
Parameters
Section titled “Parameters”TPos
Returns
Section titled “Returns”Iterable<EntityId>
queryNear
Section titled “queryNear”queryNear: (
pos,radius) =>Iterable<EntityId>
Defined in: src/spatial-structure.ts:35
All entity IDs within radius of pos (Euclidean, inclusive).
radius is in the same units as the position coordinates.
Parameters
Section titled “Parameters”TPos
radius
Section titled “radius”number
Returns
Section titled “Returns”Iterable<EntityId>
queryRect
Section titled “queryRect”queryRect: (
min,max) =>Iterable<EntityId>
Defined in: src/spatial-structure.ts:38
All entity IDs within an axis-aligned region (inclusive bounds). min / max are the region corners.
Parameters
Section titled “Parameters”TPos
TPos
Returns
Section titled “Returns”Iterable<EntityId>
remove
Section titled “remove”remove: (
id,pos) =>void
Defined in: src/spatial-structure.ts:41
Unregister an entity from a position. No-op if not present.
Parameters
Section titled “Parameters”TPos
Returns
Section titled “Returns”void