Trait valence_spatial::SpatialIndex

source ·
pub trait SpatialIndex<N = f64> {
    type Object: Bounded3D<N>;

    // Required methods
    fn query<C, F, T>(&self, collides: C, f: F) -> Option<T>
       where C: FnMut(Aabb<N>) -> bool,
             F: FnMut(&Self::Object) -> Option<T>;
    fn raycast<F>(
        &self,
        origin: Vec3<f64>,
        direction: Vec3<f64>,
        f: F,
    ) -> Option<RaycastHit<'_, Self::Object, N>>
       where F: FnMut(RaycastHit<'_, Self::Object, N>) -> bool;
}

Required Associated Types§

Required Methods§

source

fn query<C, F, T>(&self, collides: C, f: F) -> Option<T>
where C: FnMut(Aabb<N>) -> bool, F: FnMut(&Self::Object) -> Option<T>,

Invokes f with every object in the spatial index considered colliding according to collides in an arbitrary order.

collides takes an AABB and returns whether or not a collision occurred with the given AABB.

f is called with every object considered colliding. If f returns with Some(x), then query exits early with Some(x). If f never returns with Some, then query returns None.

source

fn raycast<F>( &self, origin: Vec3<f64>, direction: Vec3<f64>, f: F, ) -> Option<RaycastHit<'_, Self::Object, N>>
where F: FnMut(RaycastHit<'_, Self::Object, N>) -> bool,

Casts a ray defined by origin and direction through object AABBs and returns the closest intersection for which f returns true.

f is a predicate used to filter intersections. For instance, if a ray is shot from a player’s eye position, you probably don’t want the ray to intersect with the player’s own hitbox.

If no intersections are found or if f never returns true then None is returned. Additionally, the given ray direction must be normalized.

Object Safety§

This trait is not object safe.

Implementors§