jagua_rs/entities/
item.rs

1use std::sync::Arc;
2
3use crate::geometry::OriginalShape;
4use crate::geometry::fail_fast::SPSurrogateConfig;
5use crate::geometry::geo_enums::RotationRange;
6use crate::geometry::primitives::SPolygon;
7
8use anyhow::Result;
9
10/// Item to be produced.
11#[derive(Clone, Debug)]
12pub struct Item {
13    pub id: usize,
14    /// Original contour of the item as defined in the input
15    pub shape_orig: Arc<OriginalShape>,
16    /// Contour of the item to be used for collision detection
17    pub shape_cd: Arc<SPolygon>,
18    /// Allowed rotations in which the item can be placed
19    pub allowed_rotation: RotationRange,
20    /// The minimum quality the item should be produced out of, if `None` the item requires full quality
21    pub min_quality: Option<usize>,
22    /// Configuration for the surrogate generation
23    pub surrogate_config: SPSurrogateConfig,
24}
25
26impl Item {
27    pub fn new(
28        id: usize,
29        original_shape: OriginalShape,
30        allowed_rotation: RotationRange,
31        min_quality: Option<usize>,
32        surrogate_config: SPSurrogateConfig,
33    ) -> Result<Item> {
34        let shape_orig = Arc::new(original_shape);
35        let shape_int = {
36            let mut shape_int = shape_orig.convert_to_internal()?;
37            shape_int.generate_surrogate(surrogate_config)?;
38            Arc::new(shape_int)
39        };
40        Ok(Item {
41            id,
42            shape_orig,
43            shape_cd: shape_int,
44            allowed_rotation,
45            min_quality,
46            surrogate_config,
47        })
48    }
49
50    pub fn area(&self) -> f32 {
51        self.shape_orig.area()
52    }
53}