Clipper

Struct Clipper 

Source
pub struct Clipper<S: ClipperState = NoSubjects, P: PointScaler = Centi> { /* private fields */ }
Expand description

The Clipper struct used as a builder for applying boolean operations to paths.

Implementations§

Source§

impl<P: PointScaler> Clipper<NoSubjects, P>

Source

pub fn new() -> Clipper<NoSubjects, P>

Creates a new empty Clipper instance.

Source§

impl<P: PointScaler> Clipper<NoSubjects, P>

Source

pub fn add_subject( self, subject: impl Into<Paths<P>>, ) -> Clipper<WithSubjects, P>

Adds a subject path to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();

let clipper = Clipper::new().add_subject(path);
Source

pub fn add_open_subject( self, subject: impl Into<Paths<P>>, ) -> Clipper<WithSubjects, P>

Adds an open subject path to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();

let clipper = Clipper::new().add_open_subject(path);
Source§

impl<P: PointScaler> Clipper<WithSubjects, P>

Source

pub fn add_subject(self, subject: impl Into<Paths<P>>) -> Self

Adds another subject path to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let clipper = Clipper::new().add_subject(path).add_subject(path2);
Source

pub fn add_open_subject(self, subject: impl Into<Paths<P>>) -> Self

Adds another open subject path to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let clipper = Clipper::new().add_subject(path).add_open_subject(path2);
Source

pub fn add_clip(self, clip: impl Into<Paths<P>>) -> Clipper<WithClips, P>

Adds a clip path to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let clipper = Clipper::new().add_subject(path).add_clip(path2);
Source§

impl<P: PointScaler> Clipper<WithClips, P>

Source

pub fn add_clip(self, clip: impl Into<Paths<P>>) -> Self

Adds another clip path to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();
let path3: Paths = vec![(2.2, 2.2), (5.0, 2.2), (2.2, 5.0)].into();

let clipper = Clipper::new().add_subject(path).add_clip(path2).add_clip(path3);
Source

pub fn union(self, fill_rule: FillRule) -> Result<Paths<P>, ClipperError>

Applies a union boolean operation to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let result = Clipper::new().add_subject(path).add_clip(path2).union(FillRule::NonZero);

For more details see the original union docs.

Source

pub fn difference(self, fill_rule: FillRule) -> Result<Paths<P>, ClipperError>

Applies a difference boolean operation to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let result = Clipper::new().add_subject(path).add_clip(path2).difference(FillRule::NonZero);

For more details see the original difference docs.

Source

pub fn intersect(self, fill_rule: FillRule) -> Result<Paths<P>, ClipperError>

Applies an intersection boolean operation to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let result = Clipper::new().add_subject(path).add_clip(path2).intersect(FillRule::NonZero);

For more details see the original intersect docs.

Source

pub fn xor(self, fill_rule: FillRule) -> Result<Paths<P>, ClipperError>

Applies an xor boolean operation to the Clipper instance.

§Examples
use clipper2::*;

let path: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path2: Paths = vec![(1.2, 1.2), (4.0, 1.2), (1.2, 4.0)].into();

let result = Clipper::new().add_subject(path).add_clip(path2).xor(FillRule::NonZero);

For more details see the original xor docs.

Trait Implementations§

Source§

impl<S: Debug + ClipperState, P: Debug + PointScaler> Debug for Clipper<S, P>

Source§

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

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

impl Default for Clipper<NoSubjects, Centi>

Source§

fn default() -> Self

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

impl<S: ClipperState, P: PointScaler> Drop for Clipper<S, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S, P> Freeze for Clipper<S, P>
where S: Freeze,

§

impl<S, P> RefUnwindSafe for Clipper<S, P>

§

impl<S = NoSubjects, P = Centi> !Send for Clipper<S, P>

§

impl<S = NoSubjects, P = Centi> !Sync for Clipper<S, P>

§

impl<S, P> Unpin for Clipper<S, P>
where S: Unpin, P: Unpin,

§

impl<S, P> UnwindSafe for Clipper<S, P>
where S: UnwindSafe, 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> 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, 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.