PolyBoolean2D¶
Polygon and polyline boolean operations.
Description¶
A singleton which provides various “polygon vs. polygon” and “polyline vs. polygon” methods.
A new local instance must be created manually with new_instance method if you need to override the default parameters, else the methods in this class are available globally:
var polygons = []
# Globally.
polygons = PolyBoolean2D.merge_polygons([poly_a, poly_b])
# Locally.
var pb = PolyBoolean2D.new_instance()
pb.parameters.strictly_simple = true
polygons = pb.merge_polygons([poly_a, poly_b])
Properties¶
PolyBooleanParameters2D | parameters |
Methods¶
Array | boolean_polygons ( Array polygons_a, Array polygons_b, Operation operation ) const |
PolyNode2D | boolean_polygons_tree ( Array polygons_a, Array polygons_b, Operation operation ) const |
Array | clip_polygons ( Array polygons_a, Array polygons_b ) const |
Array | clip_polylines_with_polygons ( Array polylines, Array polygons ) const |
Array | exclude_polygons ( Array polygons_a, Array polygons_b ) const |
Array | intersect_polygons ( Array polygons_a, Array polygons_b ) const |
Array | intersect_polylines_with_polygons ( Array polylines, Array polygons ) const |
Array | merge_polygons ( Array polygons_a, Array polygons_b=null ) const |
Reference | new_instance ( ) const |
Enumerations¶
enum Operation:
- OP_NONE = 0 — No-op, but may perform polygons fixup, build hierarchy, depending on the poly_boolean implementation.
- OP_UNION = 1 — Merge (combine) polygons.
- OP_DIFFERENCE = 2 — Clip (cut) polygons or polylines.
- OP_INTERSECTION = 3 — Intersect polygons or polylines.
- OP_XOR = 4 — Mutually exclude polygons.
Property Descriptions¶
- PolyBooleanParameters2D parameters
Setter | set_parameters(value) |
Getter | get_parameters() |
Parameters to configure the default behavior of operations. Cannot be configured via the global instance, use new_instance first if you need to override the defaults.
Method Descriptions¶
Performs a boolean operation between an array of polygons, with the polygons_a
acting as the subject of the operation. Returns an array of resulting polygons with vertices in either clockwise or counterclockwise order, which determines whether a polygon is an outer polygon (boundary) or an inner polygon (hole). The orientation of returned polygons can be checked with Geometry.is_polygon_clockwise. If you need to retain the hierarchy of nested outer and inner polygons, use boolean_polygons_tree instead.
Operations:
Merges polygons into one if they overlap in any way. Passing polygons_b
is optional in this case, but you can specify a different PolyBooleanParameters2D.clip_fill_rule for these polygons, producing different results.
This operation can also be used to convert arbitrary polygons into strictly simple ones (no self-intersections).
Clips polygons, the subject remains intact if neither polygons overlap. Returns an empty array if polygons_b
completely covers polygons_a
. If polygons_b
are enclosed by polygons_a
, returns an array of boundary and hole polygons.
Intersects polygons, effectively returning the common area shared by these polygons. Returns an empty array if no intersection occurs.
Mutually excludes common area defined by the intersection of the polygons. In other words, returns all but common area between the polygons.
- PolyNode2D boolean_polygons_tree ( Array polygons_a, Array polygons_b, Operation operation ) const
Similar to boolean_polygons, but builds an hierarchy of clipped polygons and returns a top-level root node representing the tree of polygons, which has some performance cost. Whether a polygon is an outer or an inner path can be checked with PolyNode2D.is_inner more easily and effectively compared to calculating polygon area to determine orientation, see GoostGeometry2D.polygon_area.
Similar to boolean_polygons, but performs OP_DIFFERENCE between the polygons specifically.
Clips multiple polylines against polygons and returns an array of clipped polylines. This performs OP_DIFFERENCE between the polylines and the polygons. Returns an empty array if polygons completely enclose polylines.
Similar to boolean_polygons, but performs @GlobalScope.OP_XOR between the polygons specifically.
Similar to boolean_polygons, but performs OP_INTERSECTION between the polygons specifically.
Intersects multiple polylines with polygons and returns an array of intersected polylines. This performs OP_INTERSECTION between the polylines and the polygons.
Similar to boolean_polygons, but performs OP_UNION between the polygons specifically. The second parameter is optional.
- Reference new_instance ( ) const
Instantiates a new local PolyBoolean2D
instance, and parameters can be configured.