pub struct ColliderSet { /* private fields */ }Expand description
The world’s colliders, bucketed into a uniform grid for broadphase.
The grid’s cell size is the caller’s choice: it is a spatial hash bucket,
not a tile size. Cells near the typical collider size keep queries small;
much larger cells simply return more candidates, and much smaller cells make
each collider occupy more buckets. Either way the result is only a candidate
list — query reports colliders whose cells meet the
region, not colliders that actually overlap it.
Work is bounded whatever the boxes’ size: a collider spanning more than
1024 cells is not bucketed but checked by every query, and a query region
spanning more cells than the set has colliders scans the colliders
instead of the cells. A query visits at most about as many cells as the
set holds colliders, plus the oversized colliders. An inverted box (a
negative half) addresses no cells.
Implementations§
Source§impl ColliderSet
impl ColliderSet
Sourcepub fn new(cell_size: f32) -> Self
pub fn new(cell_size: f32) -> Self
An empty set bucketed at cell_size world units per grid cell.
§Panics
If cell_size is not positive and finite — an authoring error, not a
runtime condition. A zero, negative, or non-finite cell size cannot
address a grid at all.
Sourcepub fn insert(&mut self, aabb: Aabb, flags: ColliderFlags) -> usize
pub fn insert(&mut self, aabb: Aabb, flags: ColliderFlags) -> usize
Inserts a world-space collider, bucketing it into every grid cell its box overlaps (or keeping it apart when that is more than 1024 cells), and returns its index. A non-finite box addresses no cells and is never a query candidate.
Sourcepub fn get(&self, index: usize) -> Option<&Collider>
pub fn get(&self, index: usize) -> Option<&Collider>
Borrows a collider by index, as returned by query.
Sourcepub fn query(&self, region: &Aabb) -> Vec<usize>
pub fn query(&self, region: &Aabb) -> Vec<usize>
Broadphase candidates: the indices of colliders bucketed into any grid
cell that region touches.
Each index appears exactly once, in ascending order, so a caller that breaks ties by “first candidate wins” behaves identically run to run.
A region spanning more cells than the set has colliders is answered by scanning the colliders’ cell ranges, so a query visits at most about as many cells as the set holds colliders, plus the oversized colliders.