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        width: f32,
23    ) -> Result<Self> {
24        ensure!(fixed_height > 0.0, "strip height must be positive");
25        ensure!(width > 0.0, "strip width must be positive");
26        Ok(Strip {
27            fixed_height,
28            cde_config,
29            shape_modify_config,
30            width,
31        })
32    }
33
34    pub fn set_width(&mut self, width: f32) {
35        assert!(width > 0.0, "strip width must be positive");
36        self.width = width;
37    }
38}
39
40impl From<Strip> for Container {
41    fn from(s: Strip) -> Container {
42        Container::new(
43            0,
44            OriginalShape {
45                shape: SPolygon::from(Rect::try_new(0.0, 0.0, s.width, s.fixed_height).unwrap()),
46                pre_transform: DTransformation::empty(),
47                modify_mode: ShapeModifyMode::Deflate,
48                modify_config: s.shape_modify_config,
49            },
50            vec![],
51            s.cde_config,
52        )
53        .unwrap()
54    }
55}