jagua_rs/collision_detection/hazards/
filter.rs

1use crate::collision_detection::hazards::HazardEntity;
2
3/// Trait for filters to ignore all [`Hazard`](crate::collision_detection::hazards::Hazard)s induced by specific [`HazardEntity`]s.
4/// Enables collision queries to ignore specific hazards during the check.
5pub trait HazardFilter {
6    fn is_irrelevant(&self, entity: &HazardEntity) -> bool;
7}
8
9/// Deems no hazards as irrelevant.
10#[derive(Clone, Debug)]
11pub struct NoHazardFilter;
12
13/// Deems all hazards induced by the [`Container`](crate::entities::Container) as irrelevant.
14#[derive(Clone, Debug)]
15pub struct ContainerHazardFilter;
16
17/// Deems hazards induced by [`InferiorQualityZone`](crate::entities::InferiorQualityZone)s above a cutoff quality as irrelevant.
18#[derive(Clone, Debug)]
19pub struct QZHazardFilter(pub usize);
20
21/// Deems hazards induced by specific [`HazardEntity`]s as irrelevant.
22#[derive(Clone, Debug)]
23pub struct EntityHazardFilter(pub Vec<HazardEntity>);
24
25impl HazardFilter for NoHazardFilter {
26    fn is_irrelevant(&self, _entity: &HazardEntity) -> bool {
27        false
28    }
29}
30
31impl HazardFilter for ContainerHazardFilter {
32    fn is_irrelevant(&self, entity: &HazardEntity) -> bool {
33        match entity {
34            HazardEntity::PlacedItem { .. } => false,
35            HazardEntity::Exterior => true,
36            HazardEntity::Hole { .. } => true,
37            HazardEntity::InferiorQualityZone { .. } => true,
38        }
39    }
40}
41
42impl HazardFilter for EntityHazardFilter {
43    fn is_irrelevant(&self, entity: &HazardEntity) -> bool {
44        self.0.contains(entity)
45    }
46}
47
48impl HazardFilter for QZHazardFilter {
49    fn is_irrelevant(&self, entity: &HazardEntity) -> bool {
50        match entity {
51            HazardEntity::InferiorQualityZone { quality, .. } => *quality >= self.0,
52            _ => false,
53        }
54    }
55}
56
57/// Deems hazards induced by `self` as irrelevant.
58impl HazardFilter for HazardEntity {
59    fn is_irrelevant(&self, haz: &HazardEntity) -> bool {
60        self == haz
61    }
62}