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 std::borrow::Borrow;
6use std::sync::Arc;
7
8#[derive(Clone, Debug)]
11pub struct Hazard {
12 pub entity: HazardEntity,
14 pub shape: Arc<SPolygon>,
16 pub active: bool,
18}
19
20impl Hazard {
21 pub fn new(entity: HazardEntity, shape: Arc<SPolygon>) -> Self {
22 Self {
23 entity,
24 shape,
25 active: true,
26 }
27 }
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
31pub enum HazardEntity {
34 PlacedItem {
36 id: usize,
37 dt: DTransformation,
38 pk: PItemKey,
39 },
40 Exterior,
42 Hole { idx: usize },
44 InferiorQualityZone { quality: usize, idx: usize },
46}
47
48impl HazardEntity {
49 pub fn position(&self) -> GeoPosition {
52 match self {
53 HazardEntity::PlacedItem { .. } => GeoPosition::Interior,
54 HazardEntity::Exterior => GeoPosition::Exterior,
55 HazardEntity::Hole { .. } => GeoPosition::Interior,
56 HazardEntity::InferiorQualityZone { .. } => GeoPosition::Interior,
57 }
58 }
59}
60
61impl<T> From<(PItemKey, T)> for HazardEntity
62where
63 T: Borrow<PlacedItem>,
64{
65 fn from((pk, pi): (PItemKey, T)) -> Self {
66 HazardEntity::PlacedItem {
67 id: pi.borrow().item_id,
68 dt: pi.borrow().d_transf,
69 pk,
70 }
71 }
72}