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>
impl<E: HazardEntity> CDEngine<E>
Sourcepub fn new(
bbox: Rect,
static_hazards: Vec<Hazard<E>>,
config: CDEConfig,
) -> Self
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.
Sourcepub fn register_hazard(&mut self, hazard: Hazard<E>)
pub fn register_hazard(&mut self, hazard: Hazard<E>)
Registers a new hazard in the CDE.
Sourcepub fn deregister_hazard_by_entity(&mut self, hazard_entity: E) -> Hazard<E>
pub fn deregister_hazard_by_entity(&mut self, hazard_entity: E) -> Hazard<E>
Removes a hazard from the CDE.
Sourcepub fn deregister_hazard_by_key(&mut self, hkey: HazKey) -> Hazard<E>
pub fn deregister_hazard_by_key(&mut self, hkey: HazKey) -> Hazard<E>
Removes a hazard registered after construction from the CDE.
Sourcepub fn save(&self) -> CDESnapshot<E>
pub fn save(&self) -> CDESnapshot<E>
Saves the hazards registered after construction, to restore them later with
CDEngine::restore.
Sourcepub fn restore(&mut self, snapshot: &CDESnapshot<E>)
pub fn restore(&mut self, snapshot: &CDESnapshot<E>)
Restores the hazards registered after construction to those of a snapshot, keeping those present in both.
Sourcepub fn detect_poly_collision(
&self,
shape: &SPolygon,
filter: &impl HazardFilter<E>,
) -> bool
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 collisionsfilter- Hazard filter to be applied
Sourcepub fn detect_surrogate_collision(
&self,
base_surrogate: &SPSurrogate,
transform: &Transformation,
filter: &impl HazardFilter<E>,
) -> bool
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 collisionstransform- The transformation to be applied to the surrogate (on the fly)filter- Hazard filter to be applied
Sourcepub fn collect_poly_collisions(
&self,
shape: &SPolygon,
filter: &impl HazardFilter<E>,
collector: &mut impl HazardCollector<Entity = E>,
)
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 collisionsfilter- Hazards to ignorecollector- The collector to which the hazards are reported
Sourcepub fn collect_poly_collisions_until<H, C, F>(
&self,
shape: &SPolygon,
filter: &H,
collector: &mut C,
stop_after_collision: F,
) -> bool
pub fn collect_poly_collisions_until<H, C, F>( &self, shape: &SPolygon, filter: &H, collector: &mut C, stop_after_collision: F, ) -> 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.
Sourcepub fn collect_surrogate_collisions(
&self,
shape: &SPolygon,
filter: &impl HazardFilter<E>,
collector: &mut impl HazardCollector<Entity = E>,
)
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.
Sourcepub fn collect_surrogate_collisions_until<H, C, F>(
&self,
shape: &SPolygon,
filter: &H,
collector: &mut C,
stop_after_collision: F,
) -> bool
pub fn collect_surrogate_collisions_until<H, C, F>( &self, shape: &SPolygon, filter: &H, collector: &mut C, stop_after_collision: F, ) -> 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.
Sourcepub fn haz_key(&self, entity: &E) -> Option<HazKey>
pub fn haz_key(&self, entity: &E) -> Option<HazKey>
Returns the key of the hazard induced by entity, if registered.
Sourcepub fn hazards_map(&self) -> &SlotMap<HazKey, Hazard<E>>
pub fn hazards_map(&self) -> &SlotMap<HazKey, Hazard<E>>
All hazards registered in the CDE (active and inactive)
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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