jagua_rs/probs/spp/entities/
strip.rs1use 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)]
9pub 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 let id = s.width.to_bits() as usize;
43 Container::new(
44 id,
45 OriginalShape {
46 shape: SPolygon::from(Rect::try_new(0.0, 0.0, s.width, s.fixed_height).unwrap()),
47 pre_transform: DTransformation::empty(),
48 modify_mode: ShapeModifyMode::Deflate,
49 modify_config: s.shape_modify_config,
50 },
51 vec![],
52 s.cde_config,
53 )
54 .unwrap()
55 }
56}