Class PGS_ShapeBoolean
- Author:
- Michael Carleton
-
Method Summary
Modifier and TypeMethodDescriptionstatic processing.core.PShape
complement
(processing.core.PShape shape, double width, double height) Calculates the complement (or inverse) of the provided shape within a rectangular boundary of specified width and height, anchored at (0, 0).static processing.core.PShape
intersect
(processing.core.PShape a, processing.core.PShape b) Calculates the intersection of two shapes, producing a new shape representing the shared area.static processing.core.PShape
intersectMesh
(processing.core.PShape mesh, processing.core.PShape area) Performs an intersection operation between a mesh-like shape (a polygonal coverage) and a polygonal area, while preserving the individual features of the mesh during the operation.static processing.core.PShape
simpleSubtract
(processing.core.PShape shell, processing.core.PShape holes) Subtractsholes
from theshell
, without geometric processing.static processing.core.PShape
subtract
(processing.core.PShape a, processing.core.PShape b) Subtracts one shape (b) from another shape (a) and returns the resulting shape.static processing.core.PShape
subtractMesh
(processing.core.PShape mesh, processing.core.PShape area) Subtracts a polygonal area from a mesh-like shape or polygonal coverage, ensuring each individual face or feature of the mesh is preserved during the operation.static processing.core.PShape
symDifference
(processing.core.PShape a, processing.core.PShape b) Calculates the symmetric difference between two shapes.static processing.core.PShape
union
(Collection<processing.core.PShape> shapes) Performs a geometric union operation on a collection of shapes, merging them into a new shape that represents the total area of all the input shapes.static processing.core.PShape
union
(processing.core.PShape... shapes) Performs a geometric union operation on a variable number of shapes, merging them into a new shape that encompasses the total area of all input shapes.static processing.core.PShape
union
(processing.core.PShape a, processing.core.PShape b) Combines two shapes into a single new shape, representing the total area of both input shapes.static processing.core.PShape
unionMesh
(Collection<processing.core.PShape> faces) static processing.core.PShape
unionMesh
(processing.core.PShape mesh) Merges a mesh-like PShape (i.e., a GROUP PShape whose children represent faces with shared edges) into a single shape that denotes the boundary of the entire mesh.static processing.core.PShape
unionMeshWithoutHoles
(Collection<processing.core.PShape> mesh) Deprecated.This method is deprecated due to the lack of support for meshes with holes.
-
Method Details
-
intersect
public static processing.core.PShape intersect(processing.core.PShape a, processing.core.PShape b) Calculates the intersection of two shapes, producing a new shape representing the shared area.When intersecting a polygon with a path or linestring, the method will trim the path to the polygon's boundaries.
Note: When intersecting a mesh-like shape with a polygon, the remaining intersecting parts of individual faces will be collapsed into a single area. To preserve individual faces during intersection, use
intersectMesh()
.- Parameters:
a
- The first shape to be intersected.b
- The second shape to intersect with the first.- Returns:
- A new shape representing the area of intersection between the two input shapes. The resulting shape retains the style of the first input shape, 'a'.
-
intersectMesh
public static processing.core.PShape intersectMesh(processing.core.PShape mesh, processing.core.PShape area) Performs an intersection operation between a mesh-like shape (a polygonal coverage) and a polygonal area, while preserving the individual features of the mesh during the operation.When a mesh-like shape or polygonal coverage is intersected with a polygon using the general
intersect(a, b)
method, the result is a single polygon that consists of the unified or dissolved area of all intersecting mesh faces. Depending on the requirements of your task, this behavior may not be optimal. The current method addresses this issue by preserving the individual intersections of each mesh face.This method performs faster than invoking the
intersect(a, b)
method repeatedly for every face of a mesh-like shapea
against an areab
.- Parameters:
mesh
- A mesh-like GROUP shape that will be intersected with the polygonal area.area
- A polygonal shape with which the mesh will be intersected.- Returns:
- A GROUP shape where each child shape represents the union of one mesh face with the area.
- Since:
- 1.3.0
-
union
public static processing.core.PShape union(processing.core.PShape a, processing.core.PShape b) Combines two shapes into a single new shape, representing the total area of both input shapes.This method performs a geometric union operation, "gluing" the two input shapes together to create a new shape that encompasses the combined area of both inputs. If the input shapes overlap, the overlapping area is included only once in the resulting shape.
- Parameters:
a
- The first shape to be unified.b
- The second shape to be unified with the first.- Returns:
- A new PShape representing the union of the two input shapes. The resulting shape retains the style of the first input shape, 'a'.
- See Also:
-
union
Performs a geometric union operation on a collection of shapes, merging them into a new shape that represents the total area of all the input shapes. Overlapping areas among the shapes are included only once in the resulting shape.- Parameters:
shapes
- A list of PShapes to be unified.- Returns:
- A new PShape object representing the union of the input shapes.
- See Also:
-
union
public static processing.core.PShape union(processing.core.PShape... shapes) Performs a geometric union operation on a variable number of shapes, merging them into a new shape that encompasses the total area of all input shapes. Overlapping areas among the shapes are included only once in the resulting shape.- Parameters:
shapes
- A variable number of PShape instances to be unified.- Returns:
- A new PShape object representing the union of the input shapes.
- See Also:
-
unionMesh
- Parameters:
faces
- collection of faces comprising a mesh- Returns:
- A single PShape representing the boundary of the mesh.
- See Also:
-
unionMesh
public static processing.core.PShape unionMesh(processing.core.PShape mesh) Merges a mesh-like PShape (i.e., a GROUP PShape whose children represent faces with shared edges) into a single shape that denotes the boundary of the entire mesh. This method is specifically optimized for meshes and significantly outperforms other methods of unioning the mesh faces.The mesh can contain holes and these will be correctly processed and reflected in the final output.
- Parameters:
mesh
- A GROUP PShape, where each child shape forms part of a mesh, meaning they join or overlap at edges.- Returns:
- A single PShape representing the boundary of the mesh.
- Since:
- 1.2.0
-
unionMeshWithoutHoles
@Deprecated public static processing.core.PShape unionMeshWithoutHoles(Collection<processing.core.PShape> mesh) Deprecated.This method is deprecated due to the lack of support for meshes with holes.Unifies a collection of mesh shapes without handling holes, providing a more faster approach thanunionMesh(PShape)
if the input is known to have no holes.This method calculates the set of unique edges belonging to the mesh, which is equivalent to the boundary, assuming a mesh without holes. It then determines a sequential/winding order for the vertices of the boundary.
Note: This method does not account for meshes with holes.
- Parameters:
mesh
- A collection of shapes representing a mesh.- Returns:
- A new PShape representing the union of the mesh shapes.
-
subtract
public static processing.core.PShape subtract(processing.core.PShape a, processing.core.PShape b) Subtracts one shape (b) from another shape (a) and returns the resulting shape. This procedure is also known as "difference".Subtract is the opposite of
union()
.- Parameters:
a
- The PShape from which the other PShape will be subtracted.b
- The PShape that will be subtracted from the first PShape.- Returns:
- A new PShape representing the difference between the two input shapes; the new shape will have the style of shape a.
- See Also:
-
simpleSubtract
public static processing.core.PShape simpleSubtract(processing.core.PShape shell, processing.core.PShape holes) Subtractsholes
from theshell
, without geometric processing.Rather than performing geometric overlay, this method simply appends the holes as contours to the shell. For this reason, it is faster than
subtract()
but this method produces valid results only if all holes lie inside the shell and holes are not nested.- Parameters:
shell
- polygonal shapeholes
- single polygon, or GROUP shape, whose children are holes that lie within the shell- Since:
- 1.4.0
- See Also:
-
subtractMesh
public static processing.core.PShape subtractMesh(processing.core.PShape mesh, processing.core.PShape area) Subtracts a polygonal area from a mesh-like shape or polygonal coverage, ensuring each individual face or feature of the mesh is preserved during the operation.The behaviour of this method differs to
subtract(a, b)
whena
is a mesh; upon subtracting a polygon from a mesh, that method produces a single (unioned) polygon that represents the combined and dissolved area of all remaining mesh face parts. In contrast, this method preserves faces and how they are individually affected by the subtraction.This method is more efficient than repeatedly calling
subtract(a, b)
on each face of a mesh-like shape.- Parameters:
mesh
- A GROUP PShape that represents a mesh-like shape.area
- A polygonal PShape from which the mesh shape is subtracted.- Returns:
- A GROUP PShape, where each child shape is the result of the area being subtracted from a single mesh face.
- Since:
- 1.3.0
-
symDifference
public static processing.core.PShape symDifference(processing.core.PShape a, processing.core.PShape b) Calculates the symmetric difference between two shapes. The symmetric difference is the set of regions that exist in either of the two shapes but not in their intersection.- Parameters:
a
- The first shape.b
- The second shape.- Returns:
- A new shape representing the symmetric difference between the two input shapes; the new shape will have the style of shape a.
-
complement
public static processing.core.PShape complement(processing.core.PShape shape, double width, double height) Calculates the complement (or inverse) of the provided shape within a rectangular boundary of specified width and height, anchored at (0, 0).The resulting shape corresponds to the portion of the rectangle not covered by the input shape. The operation is essentially a subtraction of the input shape from the rectangle.
- Parameters:
shape
- The input shape for which the complement is to be determined.width
- The width of the rectangular boundary.height
- The height of the rectangular boundary.- Returns:
- A new PShape representing the inverse of the input shape within the specified rectangular boundary.
-