jagua_rs/collision_detection/hazards/
hazard.rs1use crate::entities::{PItemKey, PlacedItem};
2use crate::geometry::DTransformation;
3use crate::geometry::geo_enums::GeoPosition;
4use crate::geometry::primitives::SPolygon;
5use slotmap::new_key_type;
6use std::borrow::Borrow;
7use std::sync::Arc;
8
9new_key_type! {
10 pub struct HazKey;
12}
13
14#[derive(Clone, Debug)]
17pub struct Hazard {
18 pub entity: HazardEntity,
20 pub shape: Arc<SPolygon>,
22 pub dynamic: bool,
24}
25
26impl Hazard {
27 #[must_use]
28 pub fn new(entity: HazardEntity, shape: Arc<SPolygon>, dynamic: bool) -> Self {
29 Self {
30 entity,
31 shape,
32 dynamic,
33 }
34 }
35}
36
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
38pub enum HazardEntity {
41 PlacedItem {
43 id: usize,
44 dt: DTransformation,
45 pk: PItemKey,
46 },
47 Exterior,
49 Hole { idx: usize },
51 InferiorQualityZone { quality: usize, idx: usize },
53}
54
55impl HazardEntity {
56 #[must_use]
58 pub fn scope(&self) -> GeoPosition {
59 match self {
60 HazardEntity::PlacedItem { .. }
61 | HazardEntity::Hole { .. }
62 | HazardEntity::InferiorQualityZone { .. } => GeoPosition::Interior,
63 HazardEntity::Exterior => GeoPosition::Exterior,
64 }
65 }
66}
67
68impl<T> From<(PItemKey, T)> for HazardEntity
69where
70 T: Borrow<PlacedItem>,
71{
72 fn from((pk, pi): (PItemKey, T)) -> Self {
73 HazardEntity::PlacedItem {
74 id: pi.borrow().item_id,
75 dt: pi.borrow().d_transf,
76 pk,
77 }
78 }
79}