jagua_rs/probs/spp/entities/
strip.rs

1use crate::collision_detection::CDEConfig;
2use crate::entities::Container;
3use crate::geometry::primitives::{Rect, SPolygon};
4use crate::geometry::shape_modification::{ShapeModifyConfig, ShapeModifyMode};
5use crate::geometry::{DTransformation, OriginalShape};
6use anyhow::{Result, ensure};
7
8#[derive(Clone, Debug, Copy, PartialEq)]
9/// Represents a rectangular container with fixed height and variable width.
10pub struct Strip {
11    pub fixed_height: f32,
12    pub cde_config: CDEConfig,
13    pub shape_modify_config: ShapeModifyConfig,
14    pub width: f32,
15}
16
17impl Strip {
18    pub fn new(
19        fixed_height: f32,
20        cde_config: CDEConfig,
21        shape_modify_config: ShapeModifyConfig,
22    ) -> Result<Self> {
23        ensure!(fixed_height > 0.0, "strip height must be positive");
24        Ok(Strip {
25            fixed_height,
26            cde_config,
27            shape_modify_config,
28            width: 0.0,
29        })
30    }
31
32    pub fn set_width(&mut self, width: f32) {
33        self.width = width;
34    }
35}
36
37impl From<Strip> for Container {
38    fn from(s: Strip) -> Container {
39        Container::new(
40            0,
41            OriginalShape {
42                shape: SPolygon::from(Rect::try_new(0.0, 0.0, s.width, s.fixed_height).unwrap()),
43                pre_transform: DTransformation::empty(),
44                modify_mode: ShapeModifyMode::Deflate,
45                modify_config: s.shape_modify_config,
46            },
47            vec![],
48            s.cde_config,
49        )
50        .unwrap()
51    }
52}