jagua_rs/entities/
placed_item.rs

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