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 minkowski_sum(
&self,
pattern: impl Into<Path<P>>,
is_closed: bool,
) -> Self
pub fn minkowski_sum( &self, pattern: impl Into<Path<P>>, is_closed: bool, ) -> Self
Sweep pattern along every path in this set and return the
union of the per-path results.
This grows every path by an arbitrary polygonal kernel rather
than the radius-only kernel that Paths::inflate offers —
for example a square cutter, a drag-knife, or any other tool
footprint that is not disc-shaped. The kernel may be concave;
in that case the swept region can include holes.
Pass is_closed = true when the paths are closed polygons
and false for open polylines. The pattern is applied at
every vertex of every input path, so dense polylines produce
denser results than polygons with the same outer shape. The
internal per-path union uses FillRule::NonZero.
See the free function minkowski_sum for an illustrated
example.
§Examples
use clipper2::*;
let pattern: Path = vec![
(0.6, 0.0), (-0.5, 0.5), (-0.1, 0.0), (-0.5, -0.5),
].into();
let paths: Paths = vec![
vec![(1.0, 1.0), (5.0, 1.0), (5.0, 2.0),
(2.5, 2.0), (2.5, 3.5), (1.0, 3.5)],
vec![(8.0, 0.0), (12.0, 0.0), (12.0, 4.0)],
].into();
let swept = paths.minkowski_sum(pattern, true);For more details see the original Minkowski sum docs.
Sourcepub fn minkowski_diff(
&self,
pattern: impl Into<Path<P>>,
is_closed: bool,
) -> Self
pub fn minkowski_diff( &self, pattern: impl Into<Path<P>>, is_closed: bool, ) -> Self
Sweep pattern along every path in this set translating by
-p instead of +p at every vertex.
For a pattern that is symmetric about the origin this returns
the same shape as Paths::minkowski_sum. For asymmetric
patterns this is the operation behind “set of points x such
that x + pattern is contained in the input paths” — robot
footprint configuration spaces, tool reachability inside a
pocket, swept volumes for a cutter approaching from a fixed
direction.
See Paths::minkowski_sum for the meaning of is_closed
and the shape of the returned paths, and the free function
minkowski_diff for an illustrated example.
§Examples
use clipper2::*;
let pattern: Path = vec![
(0.6, 0.0), (-0.5, 0.5), (-0.1, 0.0), (-0.5, -0.5),
].into();
let paths: Paths = vec![
vec![(1.0, 1.0), (5.0, 1.0), (5.0, 2.0),
(2.5, 2.0), (2.5, 3.5), (1.0, 3.5)],
].into();
let swept = paths.minkowski_diff(pattern, true);For more details see the original Minkowski difference 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);