Skip to content

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.

TPos

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.

EntityId

TPos

void


clear: () => void

Defined in: src/spatial-structure.ts:23

Remove all entries.

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.

EntityId

TPos

TPos

void


queryAt: (pos) => Iterable<EntityId>

Defined in: src/spatial-structure.ts:29

All entity IDs at pos. Empty iterable if none.

TPos

Iterable<EntityId>


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.

TPos

number

Iterable<EntityId>


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.

TPos

TPos

Iterable<EntityId>


remove: (id, pos) => void

Defined in: src/spatial-structure.ts:41

Unregister an entity from a position. No-op if not present.

EntityId

TPos

void