pub struct Polygon { /* private fields */ }
Implementations§
Source§impl Polygon
impl Polygon
Sourcepub fn new(
initial_contour: &Vec<(f64, f64)>,
offset_size: f64,
) -> Result<Polygon, Box<dyn Error>>
pub fn new( initial_contour: &Vec<(f64, f64)>, offset_size: f64, ) -> Result<Polygon, Box<dyn Error>>
Examples found in repository?
examples/example_offsetting.rs (line 42)
23fn example_offsetting() -> Result <(), Box<dyn std::error::Error>> {
24 // The initial polygon must be closed
25 let points: Vec<(f64, f64)> = vec![
26 (0., 0.),
27 (100., 0.),
28 (40., 20.),
29 (100., 20.),
30 (100., 60.),
31 (95., 78.),
32 (55., 40.),
33 (0., 60.),
34 (0.0, 0.0)
35 ];
36
37 // The size of our margin offset, if this value is egal to 0 no offsetting will be computed
38 let offset_size: f64 = 12.25;
39 // Tolerance is the arc segments precision in polygon offsetting (rounded corner)
40 let tolerance: f64 = 0.1;
41
42 let mut polygon = Polygon::new(&points, offset_size).map_err(|e| { e })?;
43 let offset: Offset = polygon.offsetting(tolerance).map_err(|e| { e })?;
44
45 println!("Initial contour length: {:?}", points.len());
46 println!("Offset contour length: {:?}", offset.contour.len());
47 println!("Offset area: {:?}", offset.area);
48 println!("Offset perimeter: {:?}", offset.perimeter);
49
50 draw_svg_offset(
51 &points,
52 &offset,
53 "/examples/svg/",
54 "example_offsetting",
55 ).map_err(|e| {
56 print!("Error creating offset svg: {:?}", e);
57 e
58 })?;
59
60 Ok(())
61}
Sourcepub fn offsetting(&mut self, tolerance: f64) -> Result<Offset, Box<dyn Error>>
pub fn offsetting(&mut self, tolerance: f64) -> Result<Offset, Box<dyn Error>>
Examples found in repository?
examples/example_offsetting.rs (line 43)
23fn example_offsetting() -> Result <(), Box<dyn std::error::Error>> {
24 // The initial polygon must be closed
25 let points: Vec<(f64, f64)> = vec![
26 (0., 0.),
27 (100., 0.),
28 (40., 20.),
29 (100., 20.),
30 (100., 60.),
31 (95., 78.),
32 (55., 40.),
33 (0., 60.),
34 (0.0, 0.0)
35 ];
36
37 // The size of our margin offset, if this value is egal to 0 no offsetting will be computed
38 let offset_size: f64 = 12.25;
39 // Tolerance is the arc segments precision in polygon offsetting (rounded corner)
40 let tolerance: f64 = 0.1;
41
42 let mut polygon = Polygon::new(&points, offset_size).map_err(|e| { e })?;
43 let offset: Offset = polygon.offsetting(tolerance).map_err(|e| { e })?;
44
45 println!("Initial contour length: {:?}", points.len());
46 println!("Offset contour length: {:?}", offset.contour.len());
47 println!("Offset area: {:?}", offset.area);
48 println!("Offset perimeter: {:?}", offset.perimeter);
49
50 draw_svg_offset(
51 &points,
52 &offset,
53 "/examples/svg/",
54 "example_offsetting",
55 ).map_err(|e| {
56 print!("Error creating offset svg: {:?}", e);
57 e
58 })?;
59
60 Ok(())
61}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Polygon
impl RefUnwindSafe for Polygon
impl Send for Polygon
impl Sync for Polygon
impl Unpin for Polygon
impl UnwindSafe for Polygon
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more