Struct polygon_offsetting::polygon_offsetting::Polygon
source · 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)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn example_offsetting() -> Result <(), Box<dyn std::error::Error>> {
// The initial polygon must be closed
let points: Vec<(f64, f64)> = vec![
(0., 0.),
(100., 0.),
(40., 20.),
(100., 20.),
(100., 60.),
(95., 78.),
(55., 40.),
(0., 60.),
(0.0, 0.0)
];
// The size of our margin offset, if this value is egal to 0 no offsetting will be computed
let offset_size: f64 = 12.25;
// Tolerance is the arc segments precision in polygon offsetting (rounded corner)
let tolerance: f64 = 0.1;
let mut polygon = Polygon::new(&points, offset_size).map_err(|e| { e })?;
let offset: Offset = polygon.offsetting(tolerance).map_err(|e| { e })?;
println!("Initial contour length: {:?}", points.len());
println!("Offset contour length: {:?}", offset.contour.len());
println!("offset area: {:?}", offset.area);
println!("offset perimeter: {:?}", offset.perimeter);
draw_svg_offset(
&points,
&mut offset.clone(),
"/examples/svg/".to_string(),
"example_offsetting".to_string(),
).map_err(|e| {
print!("Error on creating offset svg: {:?}", e);
e
})?;
Ok(())
}
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)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn example_offsetting() -> Result <(), Box<dyn std::error::Error>> {
// The initial polygon must be closed
let points: Vec<(f64, f64)> = vec![
(0., 0.),
(100., 0.),
(40., 20.),
(100., 20.),
(100., 60.),
(95., 78.),
(55., 40.),
(0., 60.),
(0.0, 0.0)
];
// The size of our margin offset, if this value is egal to 0 no offsetting will be computed
let offset_size: f64 = 12.25;
// Tolerance is the arc segments precision in polygon offsetting (rounded corner)
let tolerance: f64 = 0.1;
let mut polygon = Polygon::new(&points, offset_size).map_err(|e| { e })?;
let offset: Offset = polygon.offsetting(tolerance).map_err(|e| { e })?;
println!("Initial contour length: {:?}", points.len());
println!("Offset contour length: {:?}", offset.contour.len());
println!("offset area: {:?}", offset.area);
println!("offset perimeter: {:?}", offset.perimeter);
draw_svg_offset(
&points,
&mut offset.clone(),
"/examples/svg/".to_string(),
"example_offsetting".to_string(),
).map_err(|e| {
print!("Error on creating offset svg: {:?}", e);
e
})?;
Ok(())
}
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