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>
impl<P: PointScaler> Paths<P>
Sourcepub fn append(&mut self, paths: impl Into<Vec<Path<P>>>)
pub fn append(&mut self, paths: impl Into<Vec<Path<P>>>)
Append another set of paths onto this one, cloning the other set.
Sourcepub fn contains_points(&self) -> bool
pub fn contains_points(&self) -> bool
Returns true
if at least one of the paths contains a point.
Sourcepub fn first(&self) -> Option<&Path<P>>
pub fn first(&self) -> Option<&Path<P>>
Returns a reference to the first path in the set of paths wrapped in an option.
Sourcepub fn get(&self, index: usize) -> Option<&Path<P>>
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.
Sourcepub fn translate(&self, x: f64, y: f64) -> Self
pub fn translate(&self, x: f64, y: f64) -> Self
Construct a clone with each point offset by a x/y distance.
Sourcepub fn scale(&self, scale_x: f64, scale_y: f64) -> Self
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.
Sourcepub fn scale_around_point(
&self,
scale_x: f64,
scale_y: f64,
point: Point<P>,
) -> Self
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.
Sourcepub fn rotate(&self, radians: f64) -> Self
pub fn rotate(&self, radians: f64) -> Self
Construct a rotated clone of the path with the origin at the path center.
Sourcepub fn inflate(
&self,
delta: f64,
join_type: JoinType,
end_type: EndType,
miter_limit: f64,
) -> Self
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.
Sourcepub fn simplify(&self, epsilon: f64, is_open: bool) -> Self
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.
Sourcepub fn to_clipper_subject(&self) -> Clipper<WithSubjects, P>
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());
Sourcepub fn to_clipper_open_subject(&self) -> Clipper<WithSubjects, P>
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());
Sourcepub fn signed_area(&self) -> f64
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);