jagua_rs/geometry/
original_shape.rs1use crate::geometry::DTransformation;
2use crate::geometry::geo_traits::Transformable;
3use crate::geometry::primitives::{Point, Rect, SPolygon};
4use crate::geometry::shape_modification::{
5 ShapeModifyConfig, ShapeModifyMode, offset_shape, simplify_shape,
6};
7use anyhow::Result;
8
9#[derive(Clone, Debug)]
10pub struct OriginalShape {
15 pub shape: SPolygon,
16 pub pre_transform: DTransformation,
17 pub modify_mode: ShapeModifyMode,
18 pub modify_config: ShapeModifyConfig,
19}
20
21impl OriginalShape {
22 pub fn convert_to_internal(&self) -> Result<SPolygon> {
23 let mut internal = self.shape.transform_clone(&self.pre_transform.compose());
25
26 if let Some(offset) = self.modify_config.offset {
27 internal = offset_shape(&internal, self.modify_mode, offset)?;
29 }
30 if let Some(tolerance) = self.modify_config.simplify_tolerance {
31 internal = simplify_shape(&internal, self.modify_mode, tolerance);
33 };
34 Ok(internal)
35 }
36
37 pub fn centroid(&self) -> Point {
38 self.shape.centroid()
39 }
40
41 pub fn area(&self) -> f32 {
42 self.shape.area
43 }
44
45 pub fn bbox(&self) -> Rect {
46 self.shape.bbox
47 }
48
49 pub fn diameter(&self) -> f32 {
50 self.shape.diameter
51 }
52}