Skip to main content

ColliderSet

Struct ColliderSet 

Source
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

Source

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.

Source

pub fn cell_size(&self) -> f32

World units per broadphase grid cell.

Source

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.

Source

pub fn get(&self, index: usize) -> Option<&Collider>

Borrows a collider by index, as returned by query.

Source

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.

Source

pub fn len(&self) -> usize

Number of colliders in the set.

Source

pub fn is_empty(&self) -> bool

Whether the set holds no colliders.

Source

pub fn clear(&mut self)

Removes every collider and its grid buckets, keeping the cell size. Indices start again from zero.

Source

pub fn iter(&self) -> Iter<'_, Collider> ⓘ

Iterates the colliders in insertion order, so position i is the collider at index i.

Trait Implementations§

Source§

impl Debug for ColliderSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a ColliderSet

Source§

type Item = &'a Collider

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Collider>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.