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