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;
7
8new_key_type! {
9 pub struct HazKey;
11}
12
13#[derive(Clone, Debug)]
16pub struct Hazard {
17 pub entity: HazardEntity,
19 pub shape: SPolygon,
21 pub dynamic: bool,
23}
24
25impl Hazard {
26 pub fn new(entity: HazardEntity, shape: SPolygon, dynamic: bool) -> Self {
27 Self {
28 entity,
29 shape,
30 dynamic,
31 }
32 }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
36pub enum HazardEntity {
39 PlacedItem {
41 id: usize,
42 dt: DTransformation,
43 pk: PItemKey,
44 },
45 Exterior,
47 Hole { idx: usize },
49 InferiorQualityZone { quality: usize, idx: usize },
51}
52
53impl HazardEntity {
54 pub fn scope(&self) -> GeoPosition {
56 match self {
57 HazardEntity::PlacedItem { .. } => GeoPosition::Interior,
58 HazardEntity::Exterior => GeoPosition::Exterior,
59 HazardEntity::Hole { .. } => GeoPosition::Interior,
60 HazardEntity::InferiorQualityZone { .. } => GeoPosition::Interior,
61 }
62 }
63}
64
65impl<T> From<(PItemKey, T)> for HazardEntity
66where
67 T: Borrow<PlacedItem>,
68{
69 fn from((pk, pi): (PItemKey, T)) -> Self {
70 HazardEntity::PlacedItem {
71 id: pi.borrow().item_id,
72 dt: pi.borrow().d_transf,
73 pk,
74 }
75 }
76}