Skip to main content

SpatialIndex2D

Struct SpatialIndex2D 

Source
pub struct SpatialIndex2D<T: Copy>(/* private fields */);
Expand description

Owned 2D collider snapshot with a balanced AABB hierarchy.

Rebuild explicitly after moving colliders. Queries see the last successful snapshot. IDs need only be Copy; the index does not read or mutate ECS components. Duplicate IDs are accepted and reported as supplied. Rebuild validates all boxes before committing, reuses staging capacity, and needs temporary room for both the old and new snapshots.

Implementations§

Source§

impl<T: Copy> SpatialIndex2D<T>

Source

pub fn new() -> Self

Creates an empty index without allocating.

Source

pub fn len(&self) -> usize

Number of indexed colliders in the last successful snapshot.

Source

pub fn is_empty(&self) -> bool

Whether the snapshot is empty.

Source

pub fn rebuild( &mut self, source: impl IntoIterator<Item = (T, Aabb2)>, ) -> Result<usize, SpatialError>

Copies (id, bounds) pairs and atomically replaces the snapshot. Invalid input returns its original position and preserves old data. Build cost is O(n log n); query cost depends on overlap distribution.

Source

pub fn nearest( &self, ray: Ray2, max_distance: f32, ) -> Result<Option<SpatialHit2<T>>, SpatialError>

Nearest ray contact within an inclusive world-unit distance. Exact-distance ties use original input order. Infinity is allowed.

Source

pub fn visit_overlapping( &self, area: Aabb2, emit: impl FnMut(T), ) -> Result<(), SpatialError>

Visits boxes with positive-volume overlap. Touching alone is excluded. Visitor order follows the hierarchy, not input order. No allocation.

Source

pub fn overlapping(&self, area: Aabb2) -> Result<Vec<T>, SpatialError>

Collects positive-volume overlaps for convenience.

Source

pub fn visit_visible(&self, view: &Frustum2D, emit: impl FnMut(T))

Visits boxes that may be visible in this camera. No allocation.

Source

pub fn visible(&self, view: &Frustum2D) -> Vec<T>

Collects potentially visible boxes for convenience.

Trait Implementations§

Source§

impl<T: Copy> Default for SpatialIndex2D<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SpatialIndex2D<T>
where Bvh<T, 2>: Freeze,

§

impl<T> RefUnwindSafe for SpatialIndex2D<T>
where Bvh<T, 2>: RefUnwindSafe,

§

impl<T> Send for SpatialIndex2D<T>
where Bvh<T, 2>: Send,

§

impl<T> Sync for SpatialIndex2D<T>
where Bvh<T, 2>: Sync,

§

impl<T> Unpin for SpatialIndex2D<T>
where Bvh<T, 2>: Unpin,

§

impl<T> UnsafeUnpin for SpatialIndex2D<T>
where Bvh<T, 2>: UnsafeUnpin,

§

impl<T> UnwindSafe for SpatialIndex2D<T>
where Bvh<T, 2>: UnwindSafe,

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> Component for T
where T: Send + Sync + 'static,

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.