pub struct CDEngine {
pub quadtree: QTNode,
pub static_hazards: Vec<Hazard>,
pub dynamic_hazards: Vec<Hazard>,
pub haz_prox_grid: Option<HazardProximityGrid>,
pub config: CDEConfig,
pub bbox: AARectangle,
pub uncommitted_deregisters: Vec<Hazard>,
}
Expand description
The Collision Detection Engine (CDE). The CDE can resolve a range of collision queries and update its state by registering and deregistering hazards.
Fields§
§quadtree: QTNode
§static_hazards: Vec<Hazard>
§dynamic_hazards: Vec<Hazard>
§haz_prox_grid: Option<HazardProximityGrid>
§config: CDEConfig
§bbox: AARectangle
§uncommitted_deregisters: Vec<Hazard>
Implementations§
Source§impl CDEngine
impl CDEngine
pub fn new( bbox: AARectangle, static_hazards: Vec<Hazard>, config: CDEConfig, ) -> CDEngine
Sourcepub fn register_hazard(&mut self, hazard: Hazard)
pub fn register_hazard(&mut self, hazard: Hazard)
Registers a new hazard in the CDE.
Sourcepub fn deregister_hazard(
&mut self,
hazard_entity: HazardEntity,
commit_instant: bool,
)
pub fn deregister_hazard( &mut self, hazard_entity: HazardEntity, commit_instant: bool, )
Removes a hazard from the CDE.
If commit_instant
the deregistration is fully executed immediately.
If not, the deregistration causes the hazard to be deactivated in the quadtree and
the hazard_proximity_grid to become dirty (and therefore inaccessible).
Can be beneficial not to commit_instant
if multiple hazards are to be deregistered, or if the chance of
restoring from a snapshot with the hazard present is high.
Call Self::commit_deregisters
to commit all uncommitted deregisters in both quadtree & hazard proximity grid
or Self::flush_haz_prox_grid
to just clear the hazard proximity grid.
pub fn create_snapshot(&mut self) -> CDESnapshot
Sourcepub fn restore(&mut self, snapshot: &CDESnapshot)
pub fn restore(&mut self, snapshot: &CDESnapshot)
Restores the CDE to a previous state, as described by the snapshot.
Sourcepub fn commit_deregisters(&mut self)
pub fn commit_deregisters(&mut self)
Commits all pending deregisters by actually removing them from the quadtree and flushing the hazard proximity grid.
pub fn quadtree(&self) -> &QTNode
pub fn number_of_nodes(&self) -> usize
pub fn bbox(&self) -> &AARectangle
pub fn smallest_qt_node_dimension(&self) -> fsize
pub fn config(&self) -> CDEConfig
Sourcepub fn haz_prox_grid(&self) -> Result<&HazardProximityGrid, DirtyState>
pub fn haz_prox_grid(&self) -> Result<&HazardProximityGrid, DirtyState>
If the grid has uncommitted deregisters, it is considered dirty and cannot be accessed.
To flush all the changes, call Self::flush_haz_prox_grid
.
Sourcepub fn flush_haz_prox_grid(&mut self)
pub fn flush_haz_prox_grid(&mut self)
Flushes all uncommitted deregisters in the HazardProximityGrid
.
pub fn has_uncommitted_deregisters(&self) -> bool
Sourcepub fn dynamic_hazards(&self) -> &Vec<Hazard>
pub fn dynamic_hazards(&self) -> &Vec<Hazard>
Returns all hazards in the CDE, which can change during the lifetime of the CDE.
Sourcepub fn static_hazards(&self) -> &Vec<Hazard>
pub fn static_hazards(&self) -> &Vec<Hazard>
Returns all hazards in the CDE, which cannot change during the lifetime of the CDE.
Sourcepub fn all_hazards(&self) -> impl Iterator<Item = &Hazard>
pub fn all_hazards(&self) -> impl Iterator<Item = &Hazard>
Returns all hazards in the CDE, both static and dynamic.
Sourcepub fn surrogate_or_poly_collides(
&self,
reference_shape: &SimplePolygon,
transform: &Transformation,
buffer_shape: &mut SimplePolygon,
irrelevant_hazards: &[HazardEntity],
) -> bool
pub fn surrogate_or_poly_collides( &self, reference_shape: &SimplePolygon, transform: &Transformation, buffer_shape: &mut SimplePolygon, irrelevant_hazards: &[HazardEntity], ) -> bool
Checks whether a reference simple polygon, with a transformation applies, collides with any of the hazards. The check is first done on the surrogate, then with the actual shape. A buffer shape is used as a temporary storage for the transformed shape.
§Arguments
reference_shape
- The shape to be checked for collisionstransform
- The transformation to be applied to the reference shapebuffer_shape
- A temporary storage for the transformed shapeirrelevant_hazards
- entities to be ignored during the check
Sourcepub fn poly_collides(
&self,
shape: &SimplePolygon,
irrelevant_hazards: &[HazardEntity],
) -> bool
pub fn poly_collides( &self, shape: &SimplePolygon, irrelevant_hazards: &[HazardEntity], ) -> bool
Checks whether a simple polygon collides with any of the (relevant) hazards
§Arguments
shape
- The shape (already transformed) to be checked for collisionsirrelevant_hazards
- entities to be ignored during the check
Sourcepub fn surrogate_collides(
&self,
base_surrogate: &SPSurrogate,
transform: &Transformation,
irrelevant_hazards: &[HazardEntity],
) -> bool
pub fn surrogate_collides( &self, base_surrogate: &SPSurrogate, transform: &Transformation, irrelevant_hazards: &[HazardEntity], ) -> bool
Checks whether a surrogate collides with any of the (relevant) hazards.
§Arguments
base_surrogate
- The (untransformed) surrogate to be checked for collisionstransform
- The transformation to be applied to the surrogateirrelevant_hazards
- entities to be ignored during the check
Sourcepub fn point_definitely_collides_with(
&self,
point: &Point,
entity: HazardEntity,
) -> Tribool
pub fn point_definitely_collides_with( &self, point: &Point, entity: HazardEntity, ) -> Tribool
Checks whether a point definitely collides with any of the (relevant) hazards. Only fully hazardous nodes in the quadtree are considered.
Sourcepub fn edge_definitely_collides(
&self,
edge: &Edge,
irrelevant_hazards: &[HazardEntity],
) -> Tribool
pub fn edge_definitely_collides( &self, edge: &Edge, irrelevant_hazards: &[HazardEntity], ) -> Tribool
Checks whether an edge definitely collides with any of the (relevant) hazards. Only fully hazardous nodes in the quadtree are considered.
Sourcepub fn circle_definitely_collides(
&self,
circle: &Circle,
irrelevant_hazards: &[HazardEntity],
) -> Tribool
pub fn circle_definitely_collides( &self, circle: &Circle, irrelevant_hazards: &[HazardEntity], ) -> Tribool
Checks whether a circle definitely collides with any of the (relevant) hazards. Only fully hazardous nodes in the quadtree are considered.
pub fn poly_or_hazard_are_contained( &self, shape: &SimplePolygon, haz: &Hazard, ) -> bool
Sourcepub fn collect_poly_collisions(
&self,
shape: &SimplePolygon,
irrelevant_hazards: &[HazardEntity],
) -> DetectionMap
pub fn collect_poly_collisions( &self, shape: &SimplePolygon, irrelevant_hazards: &[HazardEntity], ) -> DetectionMap
Collects all hazards with which the polygon collides.
Any hazards in irrelevant_hazards
are ignored.
Sourcepub fn collect_poly_collisions_in_detector(
&self,
shape: &SimplePolygon,
irrelevant_hazards: &[HazardEntity],
detector: &mut impl HazardDetector,
)
pub fn collect_poly_collisions_in_detector( &self, shape: &SimplePolygon, irrelevant_hazards: &[HazardEntity], detector: &mut impl HazardDetector, )
Collects all hazards with which the polygon collides and stores them in the detector.
Any hazards in irrelevant_hazards
are ignored, as well as hazards present in the detector before the call.
Sourcepub fn collect_surrogate_collisions(
&self,
base_surrogate: &SPSurrogate,
transform: &Transformation,
irrelevant_hazards: &[HazardEntity],
) -> DetectionMap
pub fn collect_surrogate_collisions( &self, base_surrogate: &SPSurrogate, transform: &Transformation, irrelevant_hazards: &[HazardEntity], ) -> DetectionMap
Collects all hazards with which the surrogate collides.
Any hazards in irrelevant_hazards
are ignored.
Sourcepub fn collect_surrogate_collisions_in_detector(
&self,
base_surrogate: &SPSurrogate,
transform: &Transformation,
irrelevant_hazards: &[HazardEntity],
detector: &mut impl HazardDetector,
)
pub fn collect_surrogate_collisions_in_detector( &self, base_surrogate: &SPSurrogate, transform: &Transformation, irrelevant_hazards: &[HazardEntity], detector: &mut impl HazardDetector, )
Collects all hazards with which the surrogate collides and stores them in the detector.
Any hazards in irrelevant_hazards
are ignored, as well as hazards present in the detector before the call.
Sourcepub fn collect_potential_hazards_within(
&self,
bbox: &AARectangle,
detector: &mut impl HazardDetector,
)
pub fn collect_potential_hazards_within( &self, bbox: &AARectangle, detector: &mut impl HazardDetector, )
Collects all hazards potentially colliding with the given bounding box. This is an overestimation, as it’s limited by the quadtree resolution.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CDEngine
impl RefUnwindSafe for CDEngine
impl Send for CDEngine
impl Sync for CDEngine
impl Unpin for CDEngine
impl UnwindSafe for CDEngine
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