jagua_rs/entities/
placed_item.rs

1use crate::collision_detection::hazards::filter::QZHazardFilter;
2use crate::entities::Item;
3use crate::geometry::DTransformation;
4use crate::geometry::geo_traits::Transformable;
5use crate::geometry::primitives::SPolygon;
6use slotmap::new_key_type;
7use std::sync::Arc;
8
9#[cfg(doc)]
10use crate::entities::Layout;
11
12new_key_type! {
13    /// Unique key for each [`PlacedItem`] in a layout.
14    pub struct PItemKey;
15}
16
17/// Represents an [`Item`] that has been placed in a [`Layout`]
18#[derive(Clone, Debug)]
19pub struct PlacedItem {
20    /// ID of the type of `Item` that was placed
21    pub item_id: usize,
22    /// The transformation that was applied to the `Item` before it was placed
23    pub d_transf: DTransformation,
24    /// The filter for hazards that the `Item` is unaffected by
25    pub hazard_filter: Option<QZHazardFilter>,
26    /// The shape of the `Item` after it has been transformed and placed in a `Layout`
27    pub shape: Arc<SPolygon>,
28}
29
30impl PlacedItem {
31    pub fn new(item: &Item, d_transf: DTransformation) -> Self {
32        let transf = d_transf.compose();
33        let shape = Arc::new(item.shape_cd.transform_clone(&transf));
34        let qz_haz_filter = item.hazard_filter.clone();
35
36        PlacedItem {
37            item_id: item.id,
38            d_transf,
39            shape,
40            hazard_filter: qz_haz_filter,
41        }
42    }
43}