Expand description
clipper2 is a path/polygon clipping and offsetting library that supports operations like difference, inflate, intersect, point-in-polygon, union, xor, simplify.
The create uses the clipper2c-sys crate that in turn is a Rust wrapper around the C++ version of Clipper2.
The crate exposes the Clipper API in two alternative ways until the best version has been figured out.
- Through the
Path
/Paths
struct methods:Path::inflate
Path::simplify
Path::is_point_inside
Paths::inflate
Paths::simplify
Paths::to_clipper_subject
returns aClipper
builder struct with the current set of paths as the first subject, and allowing to make boolean operations on several sets of paths in one go.Paths::to_clipper_open_subject
similar but adds the current set of paths as an open “line” rather than a closed path/polygon.
- Via the plain functions:
The Path
/Paths
structs also thas some transformation methods such
as:
Path::translate
/Paths::translate
for moving a path in by a x/y offsetPath::rotate
/Paths::rotate
for rotating a path in by x radiansPath::scale
/Paths::scale
for scaling a path by multiplier
§Examples
use clipper2::*;
let path_a: Paths = vec![(0.2, 0.2), (6.0, 0.2), (6.0, 6.0), (0.2, 6.0)].into();
let path_b: Paths = vec![(5.0, 5.0), (8.0, 5.0), (8.0, 8.0), (5.0, 8.0)].into();
let output: Vec<Vec<(f64, f64)>> = path_a
.to_clipper_subject()
.add_clip(path_b)
.difference(FillRule::default())?.
into();
dbg!(output);
More examples can be found in the examples directory.
Structs§
- Represents an area from one min and one max Point.
- Scale by 100. This is the default.
- The Clipper struct used as a builder for applying boolean operations to paths.
- Scale by 10.
- Scale by 1000.
- A state indicating no subjects and no clips.
- No scaling.
- A collection of points.
- An iterator over the points in a path.
- A collection of paths.
- An iterator over the paths.
- XY Point with custom scaler.
- A state indicating one or more subjects and one or more clips.
- A state indicating one or more subjects and no clips.
Enums§
- Errors that can occur during clipper operations.
- The EndType enumerator is only needed when offsetting (inflating/shrinking). It isn’t needed for polygon clipping.
- The Clipper Library supports 4 filling rules: Even-Odd, Non-Zero, Positive and Negative. These rules are base on the winding numbers (see below) of each polygon sub-region, which in turn are based on the orientation of each path. Orientation is determined by the order in which vertices are declared during path construction, and whether these vertices progress roughly clockwise or counter-clockwise.
- The JoinType enumeration is only needed when offsetting (inflating/shrinking). It isn’t needed for polygon clipping. It specifies how to manage offsetting at convex angled joins. Concave joins will always be offset with a mitered join.
- The result indicates whether the point is inside, or outside, or on one of the specified polygon’s edges.
Traits§
- The state of the Clipper struct.
- The point scaling trait allows to choose a multiplier for the point values at compile time.
Functions§
- This function differences closed subject paths from clip paths.
- These functions encapsulate ClipperOffset, the class that performs both polygon and open path offsetting.
- This function intersects closed subject paths with clip paths.
- The function result indicates whether the point is inside, or outside, or on one of the specified polygon’s edges.
- This function removes points that are less than the specified epsilon distance from an imaginary line that passes through its 2 adjacent points. Logically, smaller epsilon values will be less aggressive in removing points than larger epsilon values.
- This function ‘unions’ closed subject paths, with and without clip paths.
- This function ‘XORs’ closed subject paths and clip paths.