Two-dimensional cross sections guaranteed to be without self-intersections, or overlaps between polygons (from construction onwards). Polygon clipping (boolean) and offsetting use Manifold's own robust floating-point predicates.
More...
#include <cross_section.h>
Two-dimensional cross sections guaranteed to be without self-intersections, or overlaps between polygons (from construction onwards). Polygon clipping (boolean) and offsetting use Manifold's own robust floating-point predicates.
◆ JoinType
Specifies the treatment of path/contour joins (corners) when offseting CrossSections; alias of manifold::JoinType (see common.h), shared with the polygon offset implementation.
◆ 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 is performed to ensure the resulting CrossSection is free of self-intersections.
- Parameters
-
| contour | A closed path outlining the desired cross-section. |
◆ CrossSection() [4/5]
| CrossSection |
( |
const Polygons & | contours | ) |
|
Create a 2d cross-section from a set of contours (complex polygons). A boolean union operation (with the Positive filling rule) 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. |
◆ 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. |
◆ EvenOdd() [1/2]
Create a 2d cross-section from a single contour, reading it by the even-odd rule rather than the positive rule the constructors use. See CrossSection::EvenOdd(const Polygons&).
- Parameters
-
| contour | A closed path outlining the desired cross-section. |
◆ EvenOdd() [2/2]
Create a 2d cross-section from a set of contours, reading them by the even-odd rule: a sub-region is filled when its winding number is odd, so overlapping an odd number of contours fills and overlapping an even number leaves a hole. The constructors instead use the positive rule (filled where the winding number is greater than zero), which ignores contour count and only cares about direction. Use this to take input authored for an even-odd tool such as OpenSCAD.
The rule only decides how these contours are read. The result is regularized and normal-oriented like any other CrossSection, so every later operation behaves the same. Note that Manifold::Extrude and Manifold::Revolve take raw contours straight to the triangulator without applying any fill rule, so even-odd input has to be regularized here first, by passing EvenOdd(contours).ToPolygons() to them.
- Parameters
-
| contours | A set of closed paths describing zero or more complex polygons. |
◆ ToPolygons()
◆ Decompose()
This operation returns a vector of CrossSections that are topologically disconnected, each containing one outline contour with zero or more holes.
◆ 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.
◆ GetTolerance()
| double GetTolerance |
( |
| ) |
const |
◆ SetTolerance()
Return a copy with the given tolerance. Raising it decimates the geometry to the new tolerance (via Simplify); lowering it floors at the geometry's epsilon. Mirrors Manifold::SetTolerance.
◆ 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 tolerance from an imaginary line that passes through its two adjacent vertices. Near duplicate vertices and collinear points will be removed at lower tolerances, with elimination of line segments becoming increasingly aggressive with larger tolerances.
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.
- Parameters
-
| tolerance | Default 0 uses the cross-section's own tolerance (from GetTolerance()), which is geometry-scale-derived and may be larger than a fixed epsilon for large-coordinate geometry. Pass an explicit value to override. |
◆ 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. |