Skip to main content

CDEngine

Struct CDEngine 

Source
pub struct CDEngine<E = BasicHazardEntity> { /* private fields */ }
Expand description

The Collision Detection Engine (CDE). Hazards can be (de)registered and collision queries can be performed. The entity type E defines what can induce a hazard, see HazardEntity.

Implementations§

Source§

impl<E: HazardEntity> CDEngine<E>

Source

pub fn new( bbox: Rect, static_hazards: Vec<Hazard<E>>, config: CDEConfig, ) -> Self

Creates an engine with the static hazards, exactly one of which covers the exterior. Snapshots hold only the hazards registered later.

Source

pub fn register_hazard(&mut self, hazard: Hazard<E>)

Registers a new hazard in the CDE.

Source

pub fn deregister_hazard_by_entity(&mut self, hazard_entity: E) -> Hazard<E>

Removes a hazard from the CDE.

Source

pub fn deregister_hazard_by_key(&mut self, hkey: HazKey) -> Hazard<E>

Removes a hazard registered after construction from the CDE.

Source

pub fn save(&self) -> CDESnapshot<E>

Saves the hazards registered after construction, to restore them later with CDEngine::restore.

Source

pub fn restore(&mut self, snapshot: &CDESnapshot<E>)

Restores the hazards registered after construction to those of a snapshot, keeping those present in both.

Source

pub fn hazards(&self) -> impl Iterator<Item = &Hazard<E>>

Returns all hazards in the CDE

Source

pub fn detect_poly_collision( &self, shape: &SPolygon, filter: &impl HazardFilter<E>, ) -> bool

Checks whether a simple polygon collides with any of the (relevant) hazards

§Arguments
  • shape - The shape (already transformed) to be checked for collisions
  • filter - Hazard filter to be applied
Source

pub fn detect_surrogate_collision( &self, base_surrogate: &SPSurrogate, transform: &Transformation, filter: &impl HazardFilter<E>, ) -> bool

Checks whether a surrogate collides with any of the (relevant) hazards. A true result proves a collision for the represented polygon. A false result is inconclusive; follow with Self::detect_poly_collision.

§Arguments
  • base_surrogate - The (untransformed) surrogate to be checked for collisions
  • transform - The transformation to be applied to the surrogate (on the fly)
  • filter - Hazard filter to be applied
Source

pub fn collect_poly_collisions( &self, shape: &SPolygon, filter: &impl HazardFilter<E>, collector: &mut impl HazardCollector<Entity = E>, )

Collects all hazards with which the polygon collides and reports them to the collector.

§Arguments
  • shape - The shape to be checked for collisions
  • filter - Hazards to ignore
  • collector - The collector to which the hazards are reported
Source

pub fn collect_poly_collisions_until<H, C, F>( &self, shape: &SPolygon, filter: &H, collector: &mut C, stop_after_collision: F, ) -> bool
where H: HazardFilter<E>, C: HazardCollector<Entity = E>, F: FnMut(E) -> bool,

Collects polygon collisions until stop_after_collision requests an early return.

The callback receives each colliding hazard’s entity after it is added to the collector for the first time. Returning true stops traversal and leaves the collector with only the hazards found up to that point. Collision order is unspecified.

Source

pub fn collect_surrogate_collisions( &self, shape: &SPolygon, filter: &impl HazardFilter<E>, collector: &mut impl HazardCollector<Entity = E>, )

Collects collisions found by the surrogate screening pass.

This checks a prefix of the largest poles, not the complete polygon. Follow it with Self::collect_poly_collisions when every collision must be collected.

Source

pub fn collect_surrogate_collisions_until<H, C, F>( &self, shape: &SPolygon, filter: &H, collector: &mut C, stop_after_collision: F, ) -> bool
where H: HazardFilter<E>, C: HazardCollector<Entity = E>, F: FnMut(E) -> bool,

Collects collisions found by the surrogate screening pass until stop_after_collision requests an early return.

The callback contract matches Self::collect_poly_collisions_until. The configured fail-fast poles are checked against the exterior first, then against the other hazards in index order, not by pole size. This is not a complete polygon collision query; follow it with Self::collect_poly_collisions_until if the callback does not stop the screening pass.

Source

pub fn bbox(&self) -> Rect

Shapes reaching outside this rectangle collide with the exterior.

Source

pub fn haz_key(&self, entity: &E) -> Option<HazKey>

Returns the key of the hazard induced by entity, if registered.

Source

pub fn hazards_map(&self) -> &SlotMap<HazKey, Hazard<E>>

All hazards registered in the CDE (active and inactive)

Source

pub fn hazard(&self, key: HazKey) -> Option<&Hazard<E>>

Returns the registered hazard, or None if the key is no longer valid.

Source

pub fn config(&self) -> CDEConfig

Configuration of the CDE

Trait Implementations§

Source§

impl<E: Clone> Clone for CDEngine<E>

Source§

fn clone(&self) -> CDEngine<E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Debug> Debug for CDEngine<E>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E> Freeze for CDEngine<E>

§

impl<E> RefUnwindSafe for CDEngine<E>
where E: RefUnwindSafe,

§

impl<E> Send for CDEngine<E>
where E: Send,

§

impl<E> Sync for CDEngine<E>
where E: Sync,

§

impl<E> Unpin for CDEngine<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for CDEngine<E>

§

impl<E> UnwindSafe for CDEngine<E>
where E: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool