Class
NaiveBroadphase2D
View sourceProvides a simple in-memory 2D broadphase for a small number of bodies.
The implementation keeps each EntityHandle beside its
PhysicsHitbox and scans every stored entry for each query. It is
intended for small collections, such as a scene with fewer than about 100
bodies, where a linear scan is sufficient.
Box and circle queries test the stored bounds against their respective
regions. Rebuild the index by calling NaiveBroadphase2D#clear
and then adding the current entity bounds with
NaiveBroadphase2D#push. The point-query method currently does
not perform a point test and returns its target array unchanged.
Examples
import { BoundingBox2D } from '@wimaengine/geometry'
import { World } from '@wimaengine/ecs'
import { NaiveBroadphase2D, PhysicsHitbox } from '@wimaengine/broadphase'
const world = new World()
const entity = world.spawn([])
const broadphase = new NaiveBroadphase2D()
broadphase.push(entity, new PhysicsHitbox(-1, -1, 1, 1))
const candidates = broadphase.queryBox(new BoundingBox2D(-2, -2, 2, 2))Constructor
Methods
queryBox(bound: BoundingBox2D, target?: EntityHandle[]): EntityHandle[]
View sourceFinds stored entities whose bounds overlap an axis-aligned box.
Matches are appended to target, so an existing result array can be
reused across queries.
queryCircle(bound: BoundingCircle, target?: EntityHandle[]): EntityHandle[]
View sourceFinds stored entities whose bounds overlap a circle.
Matches are appended to target, so an existing result array can be
reused across queries.
queryPoint(_point: Vector2, target?: EntityHandle[]): EntityHandle[]
View sourceReturns the point-query target without testing stored bounds.
Point matching is not implemented yet. The supplied point is ignored and no entities are appended.
clear(): void
View sourceRemoves all entities and bounds from the in-memory index.
Call this before pushing the current broadphase entries when rebuilding the index for a new world state.
push(entity: EntityHandle, bound: PhysicsHitbox): void
View sourceAdds an entity and its current PhysicsHitbox to the index.
The bound is retained by reference until the index is cleared or the entry is replaced by a new rebuild.
