Two-dimensional cross sections guaranteed to be without self-intersections, or overlaps between polygons (from construction onwards). This class makes use of the Clipper2 library for polygon clipping (boolean) and offsetting operations.
More...
#include <cross_section.h>
Two-dimensional cross sections guaranteed to be without self-intersections, or overlaps between polygons (from construction onwards). This class makes use of the Clipper2 library for polygon clipping (boolean) and offsetting operations.
◆ FillRule
Filling rules defining which polygon sub-regions are considered to be inside a given polygon, and which sub-regions will not (based on winding numbers). See the Clipper2 docs for a detailed explaination with illusrations.
| Enumerator |
|---|
| EvenOdd | Only odd numbered sub-regions are filled.
|
| NonZero | Only non-zero sub-regions are filled.
|
| Positive | Only sub-regions with winding counts > 0 are filled.
|
| Negative | Only sub-regions with winding counts < 0 are filled.
|
◆ JoinType
Specifies the treatment of path/contour joins (corners) when offseting CrossSections. See the Clipper2 doc for illustrations.
| Enumerator |
|---|
| Square | Squaring is applied uniformly at all joins where the internal join angle is less that 90 degrees. The squared edge will be at exactly the offset distance from the join vertex.
|
| Round | Rounding is applied to all joins that have convex external angles, and it maintains the exact offset distance from the join vertex.
|
| Miter | There's a necessary limit to mitered joins (to avoid narrow angled joins producing excessively long and narrow spikes). So where mitered joins would exceed a given maximum miter distance (relative to the offset distance), these are 'squared' instead.
|
| Bevel | Bevelled joins are similar to 'squared' joins except that squaring won't occur at a fixed distance. While bevelled joins may not be as pretty as squared joins, bevelling is much easier (ie faster) than squaring. And perhaps this is why bevelling rather than squaring is preferred in numerous graphics display formats (including SVG and PDF document formats).
|
◆ CrossSection() [1/5]
The default constructor is an empty cross-section (containing no contours).
◆ CrossSection() [2/5]
| CrossSection |
( |
const CrossSection & | other | ) |
|
The copy constructor avoids copying the underlying paths vector (sharing with its parent via shared_ptr), however subsequent transformations, and their application will not be shared. It is generally recommended to avoid this, opting instead to simply create CrossSections with the available const methods.
◆ CrossSection() [3/5]
Create a 2d cross-section from a single contour. A boolean union operation (with Positive filling rule by default) is performed to ensure the resulting CrossSection is free of self-intersections.
- Parameters
-
| contour | A closed path outlining the desired cross-section. |
| fillrule | The filling rule used to interpret polygon sub-regions created by self-intersections in contour. |
◆ CrossSection() [4/5]
Create a 2d cross-section from a set of contours (complex polygons). A boolean union operation (with Positive filling rule by default) is performed to combine overlapping polygons and ensure the resulting CrossSection is free of intersections.
- Parameters
-
| contours | A set of closed paths describing zero or more complex polygons. |
| fillrule | The filling rule used to interpret polygon sub-regions in contours. |
◆ CrossSection() [5/5]
| CrossSection |
( |
const Rect & | rect | ) |
|
Create a 2d cross-section from an axis-aligned rectangle (bounding box).
- Parameters
-
| rect | An axis-aligned rectangular bounding box. |
◆ ToPolygons()
◆ Decompose()
This operation returns a vector of CrossSections that are topologically disconnected, each containing one outline contour with zero or more holes.
◆ Compose()
Construct a CrossSection from a vector of other CrossSections (batch boolean union).
◆ Square()
| CrossSection Square |
( |
const vec2 | size, |
|
|
bool | center = false ) |
|
static |
Constructs a square with the given XY dimensions. By default it is positioned in the first quadrant, touching the origin. If any dimensions in size are negative, or if all are zero, an empty Manifold will be returned.
- Parameters
-
| size | The X, and Y dimensions of the square. |
| center | Set to true to shift the center to the origin. |
◆ Circle()
| CrossSection Circle |
( |
double | radius, |
|
|
int | circularSegments = 0 ) |
|
static |
Constructs a circle of a given radius.
- Parameters
-
| radius | Radius of the circle. Must be positive. |
| circularSegments | Number of segments along its diameter. Default is calculated by the static Quality defaults according to the radius. |
◆ IsEmpty()
◆ NumVert()
◆ NumContour()
| size_t NumContour |
( |
| ) |
const |
Return the number of contours (both outer and inner paths) in the CrossSection.
◆ Bounds()
Returns the axis-aligned bounding rectangle of all the CrossSections' vertices.
◆ Area()
Return the total area covered by complex polygons making up the CrossSection.
◆ Translate()
Move this CrossSection in space. This operation can be chained. Transforms are combined and applied lazily.
- Parameters
-
| v | The vector to add to every vertex. |
◆ Rotate()
Applies a (Z-axis) rotation to the CrossSection, in degrees. This operation can be chained. Transforms are combined and applied lazily.
- Parameters
-
| degrees | degrees about the Z-axis to rotate. |
◆ Scale()
Scale this CrossSection in space. This operation can be chained. Transforms are combined and applied lazily.
- Parameters
-
| scale | The vector to multiply every vertex by per component. |
◆ Mirror()
Mirror this CrossSection over the arbitrary axis whose normal is described by the unit form of the given vector. If the length of the vector is zero, an empty CrossSection is returned. This operation can be chained. Transforms are combined and applied lazily.
- Parameters
-
| ax | the axis to be mirrored over |
◆ Transform()
Transform this CrossSection in space. The first two columns form a 2x2 matrix transform and the last is a translation vector. This operation can be chained. Transforms are combined and applied lazily.
- Parameters
-
| m | The affine transform matrix to apply to all the vertices. |
◆ Warp()
| CrossSection Warp |
( |
std::function< void(vec2 &)> | warpFunc | ) |
const |
Move the vertices of this CrossSection (creating a new one) according to any arbitrary input function, followed by a union operation (with a Positive fill rule) that ensures any introduced intersections are not included in the result.
- Parameters
-
| warpFunc | A function that modifies a given vertex position. |
◆ WarpBatch()
Same as CrossSection::Warp but calls warpFunc with a VecView which is roughly equivalent to std::span pointing to all vec2 elements to be modified in-place
- Parameters
-
| warpFunc | A function that modifies multiple vertex positions. |
◆ Simplify()
Remove vertices from the contours in this CrossSection that are less than the specified distance epsilon from an imaginary line that passes through its two adjacent vertices. Near duplicate vertices and collinear points will be removed at lower epsilons, with elimination of line segments becoming increasingly aggressive with larger epsilons.
It is recommended to apply this function following Offset, in order to clean up any spurious tiny line segments introduced that do not improve quality in any meaningful way. This is particularly important if further offseting operations are to be performed, which would compound the issue.
◆ Offset()
Inflate the contours in CrossSection by the specified delta, handling corners according to the given JoinType.
- Parameters
-
| delta | Positive deltas will cause the expansion of outlining contours to expand, and retraction of inner (hole) contours. Negative deltas will have the opposite effect. |
| jointype | The join type specifying the treatment of contour joins (corners). Defaults to Round. |
| miter_limit | The maximum distance in multiples of delta that vertices can be offset from their original positions with before squaring is applied, when the join type is Miter (default is 2, which is the minimum allowed). See the Clipper2 MiterLimit page for a visual example. |
| circularSegments | Number of segments per 360 degrees of JoinType::Round corners (roughly, the number of vertices that will be added to each contour). Default is calculated by the static Quality defaults according to the radius. |
◆ Boolean()
Perform the given boolean operation between this and another CrossSection.
◆ BatchBoolean()
Perform the given boolean operation on a list of CrossSections. In case of Subtract, all CrossSections in the tail are differenced from the head.
◆ operator+()
Compute the boolean union between two cross-sections.
◆ operator+=()
Compute the boolean union between two cross-sections, assigning the result to the first.
◆ operator-()
Compute the boolean difference of a (clip) cross-section from another (subject).
◆ operator-=()
Compute the boolean difference of a (clip) cross-section from a another (subject), assigning the result to the subject.
◆ operator^()
Compute the boolean intersection between two cross-sections.
◆ operator^=()
Compute the boolean intersection between two cross-sections, assigning the result to the first.
◆ Hull() [1/4]
Compute the convex hull of this cross-section.
◆ Hull() [2/4]
Compute the convex hull enveloping a set of cross-sections.
- Parameters
-
| crossSections | A vector of cross-sections over which to compute a convex hull. |
◆ Hull() [3/4]
Compute the convex hull of a set of points. If the given points are fewer than 3, an empty CrossSection will be returned.
- Parameters
-
| pts | A vector of 2-dimensional points over which to compute a convex hull. |
◆ Hull() [4/4]
Compute the convex hull of a set of points/polygons. If the given points are fewer than 3, an empty CrossSection will be returned.
- Parameters
-
| polys | A vector of vectors of 2-dimensional points over which to compute a convex hull. |