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 if offset != 0.0 {
29 internal = offset_shape(&internal, self.modify_mode, offset)?;
30 }
31 }
32 if let Some(tolerance) = self.modify_config.simplify_tolerance {
33 internal = simplify_shape(&internal, self.modify_mode, tolerance);
35 };
36 Ok(internal)
37 }
38
39 pub fn centroid(&self) -> Point {
40 self.shape.centroid()
41 }
42
43 pub fn area(&self) -> f32 {
44 self.shape.area
45 }
46
47 pub fn bbox(&self) -> Rect {
48 self.shape.bbox
49 }
50
51 pub fn diameter(&self) -> f32 {
52 self.shape.diameter
53 }
54}