Struct Paths

Source
pub struct Paths<P: PointScaler = Centi>(/* private fields */);
Expand description

A collection of paths.

§Examples

use clipper2::*;

let paths_from_single_vec: Paths = vec![(0.0, 0.0), (5.0, 0.0), (5.0, 6.0), (0.0, 6.0)].into();
let paths_from_vec_of_vecs: Paths = vec![vec![(0.0, 0.0), (5.0, 0.0), (5.0, 6.0), (0.0, 6.0)]].into();

Implementations§

Source§

impl<P: PointScaler> Paths<P>

Source

pub fn new(paths: Vec<Path<P>>) -> Self

Create a new paths from a vector of paths.

Source

pub fn push(&mut self, paths: impl Into<Paths<P>>)

In place push paths onto this set of paths.

Source

pub fn append(&mut self, paths: impl Into<Vec<Path<P>>>)

Append another set of paths onto this one, cloning the other set.

Source

pub fn len(&self) -> usize

Returns the number of paths.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no paths added.

Source

pub fn contains_points(&self) -> bool

Returns true if at least one of the paths contains a point.

Source

pub fn first(&self) -> Option<&Path<P>>

Returns a reference to the first path in the set of paths wrapped in an option.

Source

pub fn get(&self, index: usize) -> Option<&Path<P>>

Returns a reference to the path at the given index in the set of paths wrapped in an option.

Source

pub fn iter(&self) -> Iter<'_, Path<P>>

Returns an iterator over the paths in the paths.

Source

pub fn translate(&self, x: f64, y: f64) -> Self

Construct a clone with each point offset by a x/y distance.

Source

pub fn scale(&self, scale_x: f64, scale_y: f64) -> Self

Construct a scaled clone of the path with the origin at the path center.

Source

pub fn scale_around_point( &self, scale_x: f64, scale_y: f64, point: Point<P>, ) -> Self

Construct a scaled clone of the path with the origin at a given point.

Source

pub fn rotate(&self, radians: f64) -> Self

Construct a rotated clone of the path with the origin at the path center.

Source

pub fn flip_x(&self) -> Self

Construct a clone with each point x value flipped.

Source

pub fn flip_y(&self) -> Self

Construct a clone with each point y value flipped.

Source

pub fn bounds(&self) -> Bounds<P>

Returns the bounds for this path.

Source

pub fn inflate( &self, delta: f64, join_type: JoinType, end_type: EndType, miter_limit: f64, ) -> Self

Construct a new set of paths offset from this one by a delta distance.

For closed paths passing a positive delta number will inflate the path where passing a negative number will shrink the path.

NOTE: Inflate calls will frequently generate a large amount of very close extra points and it is therefore recommented to almost always call Paths::simplify on the path after inflating/shrinking it.

§Examples
use clipper2::*;

let paths: Paths = vec![vec![(0.0, 0.0), (5.0, 0.0), (5.0, 6.0), (0.0, 6.0)]].into();
let inflated = paths
    .inflate(1.0, JoinType::Square, EndType::Polygon, 2.0)
    .simplify(0.01, false);

For more details see the original inflate paths docs.

Source

pub fn simplify(&self, epsilon: f64, is_open: bool) -> Self

Construct a new set of paths from these ones but with a reduced set of points.

§Examples
use clipper2::*;

let paths: Paths = vec![vec![(0.0, 0.0), (5.0, 0.002), (5.0, 0.01), (5.1, 0.0), (5.0, 6.0), (0.0, 6.0)]].into();
let simplified = paths.simplify(1.0, true);

For more details see the original simplify docs.

Source

pub fn to_clipper_subject(&self) -> Clipper<WithSubjects, P>

Create a Clipper builder with this set of paths as the subject that will allow for making boolean operations on this set of paths.

§Examples
use clipper2::*;

let path: Paths = vec![vec![(0.0, 0.0), (5.0, 6.0), (0.0, 6.0)]].into();
let path2: Paths = vec![vec![(1.0, 1.0), (4.0, 1.0), (1.0, 4.0)]].into();
let result = path.to_clipper_subject().add_clip(path2).union(FillRule::default());
Source

pub fn to_clipper_open_subject(&self) -> Clipper<WithSubjects, P>

Create a Clipper builder with this set of paths as the open subject that will allow for making boolean operations on this set of paths.

§Examples
use clipper2::*;

let path: Paths =  vec![vec![(0.0, 0.0), (5.0, 6.0), (0.0, 6.0)]].into();
let path2: Paths = vec![vec![(1.0, 1.0), (4.0, 1.0), (1.0, 4.0)]].into();
let result = path.to_clipper_open_subject().add_clip(path2).difference(FillRule::default());
Source

pub fn signed_area(&self) -> f64

This function returns the area of the supplied paths. It’s assumed that the paths are closed and do not self-intersect.

Depending on the paths’ winding orientations, this value may be positive or negative. Assuming paths are displayed in a Cartesian plane (with X values increasing heading right and Y values increasing heading up) then clockwise winding will have negative areas and counter-clockwise winding have positive areas.

Conversely, when paths are displayed where Y values increase heading down, then clockwise paths will have positive areas, and counter-clockwise paths will have negative areas.

§Examples
use clipper2::*;

let paths: Paths = vec![vec![(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]].into();

assert_eq!(paths.signed_area(), 1.0);

Trait Implementations§

Source§

impl<P: Clone + PointScaler> Clone for Paths<P>

Source§

fn clone(&self) -> Paths<P>

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<P: Debug + PointScaler> Debug for Paths<P>

Source§

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

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

impl<P: Default + PointScaler> Default for Paths<P>

Source§

fn default() -> Paths<P>

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

impl<P: PointScaler> From<Path<P>> for Paths<P>

Source§

fn from(path: Path<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Paths<P>> for Vec<Path<P>>

Source§

fn from(paths: Paths<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Paths<P>> for Vec<Vec<[f64; 2]>>

Source§

fn from(paths: Paths<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Paths<P>> for Vec<Vec<(f64, f64)>>

Source§

fn from(paths: Paths<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<[f64; 2]>> for Paths<P>

Source§

fn from(points: Vec<[f64; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<(f64, f64)>> for Paths<P>

Source§

fn from(points: Vec<(f64, f64)>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<Path<P>>> for Paths<P>

Source§

fn from(points: Vec<Path<P>>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<Point<P>>> for Paths<P>

Source§

fn from(points: Vec<Point<P>>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<Vec<[f64; 2]>>> for Paths<P>

Source§

fn from(points: Vec<Vec<[f64; 2]>>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<Vec<(f64, f64)>>> for Paths<P>

Source§

fn from(points: Vec<Vec<(f64, f64)>>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> From<Vec<Vec<Point<P>>>> for Paths<P>

Source§

fn from(points: Vec<Vec<Point<P>>>) -> Self

Converts to this type from the input type.
Source§

impl<P: PointScaler> FromIterator<Path<P>> for Paths<P>

Source§

fn from_iter<T: IntoIterator<Item = Path<P>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<P: Hash + PointScaler> Hash for Paths<P>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<P: PointScaler> IntoIterator for Paths<P>

Source§

type Item = Path<P>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Paths<P> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<P: PartialEq + PointScaler> PartialEq for Paths<P>

Source§

fn eq(&self, other: &Paths<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Eq + PointScaler> Eq for Paths<P>

Source§

impl<P: PointScaler> StructuralPartialEq for Paths<P>

Auto Trait Implementations§

§

impl<P> Freeze for Paths<P>

§

impl<P> RefUnwindSafe for Paths<P>
where P: RefUnwindSafe,

§

impl<P> Send for Paths<P>
where P: Send,

§

impl<P> Sync for Paths<P>
where P: Sync,

§

impl<P> Unpin for Paths<P>
where P: Unpin,

§

impl<P> UnwindSafe for Paths<P>
where P: UnwindSafe,

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.