Struct Polygon

Source
pub struct Polygon { /* private fields */ }

Implementations§

Source§

impl Polygon

Source

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}
Source

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§

Source§

impl Clone for Polygon

Source§

fn clone(&self) -> Polygon

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Polygon

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Polygon

Source§

fn default() -> Polygon

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.