jagua_rs/entities/
item.rs

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