diff options
author | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2019-05-18 20:01:42 +0300 |
---|---|---|
committer | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2019-05-22 17:12:39 +0300 |
commit | 883ef8570a52977e507bf43e5a8382c8b7afee06 (patch) | |
tree | 2b80121fdeb803dc265b6aa98c859ddf1a69368f /doc/classes/Geometry.xml | |
parent | fa5cc1da7a83ca7bdf685ba243e207bcd5de7370 (diff) |
Expose 2D polygon boolean operations in Geometry singleton
Clipper 6.4.2 is used internally to perform polypaths clipping, as well
as inflating/deflating polypaths. The following methods were added:
```
Geometry.merge_polygons_2d(poly_a, poly_b) # union
Geometry.clip_polygons_2d(poly_a, poly_b) # difference
Geometry.intersect_polygons_2d(poly_a, poly_b) # intersection
Geometry.exclude_polygons_2d(poly_a, poly_b) # xor
Geometry.clip_polyline_with_polygon_2d(poly_a, poly_b)
Geometry.intersect_polyline_with_polygon_2d(poly_a, poly_b)
Geometry.offset_polygon_2d(polygon, delta) # inflate/deflate
Geometry.offset_polyline_2d(polyline, delta) # returns polygons
// This one helps to implement CSG-like behaviour:
Geometry.transform_points_2d(points, transform)
```
All the methods return an array of polygons/polylines. The resulting
polygons could possibly be holes which could be checked with
`Geometry.is_polygon_clockwise()` which was exposed to scripting as well.
Diffstat (limited to 'doc/classes/Geometry.xml')
-rw-r--r-- | doc/classes/Geometry.xml | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/doc/classes/Geometry.xml b/doc/classes/Geometry.xml index 68539d7ecb..b95b888cf1 100644 --- a/doc/classes/Geometry.xml +++ b/doc/classes/Geometry.xml @@ -59,6 +59,29 @@ Clips the polygon defined by the points in [code]points[/code] against the [code]plane[/code] and returns the points of the clipped polygon. </description> </method> + <method name="clip_polygons_2d"> + <return type="Array"> + </return> + <argument index="0" name="polygon_a" type="PoolVector2Array"> + </argument> + <argument index="1" name="polygon_b" type="PoolVector2Array"> + </argument> + <description> + Clips [code]polygon_a[/code] against [code]polygon_b[/code] and returns an array of clipped polygons. This performs [code]OPERATION_DIFFERENCE[/code] between polygons. Returns an empty array if [code]polygon_b[/code] completely overlaps [code]polygon_a[/code]. + If [code]polygon_b[/code] is enclosed by [code]polygon_a[/code], returns an outer polygon (boundary) and inner polygon (hole) which could be distiguished by calling [method is_polygon_clockwise]. + </description> + </method> + <method name="clip_polyline_with_polygon_2d"> + <return type="Array"> + </return> + <argument index="0" name="polyline" type="PoolVector2Array"> + </argument> + <argument index="1" name="polygon" type="PoolVector2Array"> + </argument> + <description> + Clips [code]polyline[/code] against [code]polygon[/code] and returns an array of clipped polylines. This performs [code]OPERATION_DIFFERENCE[/code] between the polyline and the polygon. This operation can be thought of as cutting a line with a closed shape. + </description> + </method> <method name="convex_hull_2d"> <return type="PoolVector2Array"> </return> @@ -68,6 +91,18 @@ Given an array of [Vector2]s, returns the convex hull as a list of points in counter-clockwise order. The last point is the same as the first one. </description> </method> + <method name="exclude_polygons_2d"> + <return type="Array"> + </return> + <argument index="0" name="polygon_a" type="PoolVector2Array"> + </argument> + <argument index="1" name="polygon_b" type="PoolVector2Array"> + </argument> + <description> + Mutually excludes common area defined by intersection of [code]polygon_a[/code] and [code]polygon_b[/code] (see [method intersect_polygons_2d]) and returns an array of excluded polygons. This performs [code]OPERATION_XOR[/code] between polygons. In other words, returns all but common area between polygons. + The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise]. + </description> + </method> <method name="get_closest_point_to_segment"> <return type="Vector3"> </return> @@ -158,6 +193,38 @@ <description> </description> </method> + <method name="intersect_polygons_2d"> + <return type="Array"> + </return> + <argument index="0" name="polygon_a" type="PoolVector2Array"> + </argument> + <argument index="1" name="polygon_b" type="PoolVector2Array"> + </argument> + <description> + Intersects [code]polygon_a[/code] with [code]polygon_b[/code] and returns an array of intersected polygons. This performs [code]OPERATION_INTERSECTION[/code] between polygons. In other words, returns common area shared by polygons. Returns an empty array if no intersection occurs. + The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise]. + </description> + </method> + <method name="intersect_polyline_with_polygon_2d"> + <return type="Array"> + </return> + <argument index="0" name="polyline" type="PoolVector2Array"> + </argument> + <argument index="1" name="polygon" type="PoolVector2Array"> + </argument> + <description> + Intersects [code]polyline[/code] with [code]polygon[/code] and returns an array of intersected polylines. This performs [code]OPERATION_INTERSECTION[/code] between the polyline and the polygon. This operation can be thought of as chopping a line with a closed shape. + </description> + </method> + <method name="is_polygon_clockwise"> + <return type="bool"> + </return> + <argument index="0" name="polygon" type="PoolVector2Array"> + </argument> + <description> + Returns [code]true[/code] if [code]polygon[/code]'s vertices are ordered in clockwise order, otherwise returns [code]false[/code]. + </description> + </method> <method name="line_intersects_line_2d"> <return type="Variant"> </return> @@ -182,6 +249,51 @@ Given an array of [Vector2]s representing tiles, builds an atlas. The returned dictionary has two keys: [code]points[/code] is a vector of [Vector2] that specifies the positions of each tile, [code]size[/code] contains the overall size of the whole atlas as [Vector2]. </description> </method> + <method name="merge_polygons_2d"> + <return type="Array"> + </return> + <argument index="0" name="polygon_a" type="PoolVector2Array"> + </argument> + <argument index="1" name="polygon_b" type="PoolVector2Array"> + </argument> + <description> + Merges (combines) [code]polygon_a[/code] and [code]polygon_b[/code] and returns an array of merged polygons. This performs [code]OPERATION_UNION[/code] between polygons. + The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise]. + </description> + </method> + <method name="offset_polygon_2d"> + <return type="Array"> + </return> + <argument index="0" name="polygon" type="PoolVector2Array"> + </argument> + <argument index="1" name="delta" type="float"> + </argument> + <argument index="2" name="join_type" type="int" enum="Geometry.PolyJoinType" default="0"> + </argument> + <description> + Inflates or deflates [code]polygon[/code] by [code]delta[/code] units (pixels). If [code]delta[/code] is positive, makes the polygon grow outward. If [code]delta[/code] is negative, shrinks the polygon inward. Returns an array of polygons because inflating/deflating may result in multiple discrete polygons. Returns an empty array if [code]delta[/code] is negative and the absolute value of it approximately exceeds the minimum bounding rectangle dimensions of the polygon. + Each polygon's vertices will be rounded as determined by [code]join_type[/code], see [enum Geometry.PolyJoinType]. + The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise]. + </description> + </method> + <method name="offset_polyline_2d"> + <return type="Array"> + </return> + <argument index="0" name="polyline" type="PoolVector2Array"> + </argument> + <argument index="1" name="delta" type="float"> + </argument> + <argument index="2" name="join_type" type="int" enum="Geometry.PolyJoinType" default="0"> + </argument> + <argument index="3" name="end_type" type="int" enum="Geometry.PolyEndType" default="3"> + </argument> + <description> + Inflates or deflates [code]polyline[/code] by [code]delta[/code] units (pixels), producing polygons. If [code]delta[/code] is positive, makes the polyline grow outward. Returns an array of polygons because inflating/deflating may result in multiple discrete polygons. If [code]delta[/code] is negative, returns an empty array. + Each polygon's vertices will be rounded as determined by [code]join_type[/code], see [enum Geometry.PolyJoinType]. + Each polygon's endpoints will be rounded as determined by [code]end_type[/code], see [enum Geometry.PolyEndType]. + The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise]. + </description> + </method> <method name="point_is_inside_triangle" qualifiers="const"> <return type="bool"> </return> @@ -304,6 +416,18 @@ Tests if the segment ([code]from[/code], [code]to[/code]) intersects the triangle [code]a[/code], [code]b[/code], [code]c[/code]. If yes, returns the point of intersection as [Vector3]. If no intersection takes place, an empty [Variant] is returned. </description> </method> + <method name="transform_points_2d"> + <return type="PoolVector2Array"> + </return> + <argument index="0" name="points" type="PoolVector2Array"> + </argument> + <argument index="1" name="transform" type="Transform2D"> + </argument> + <description> + Transforms an array of points by [code]transform[/code] and returns the result. + Can be useful in conjuction with performing polygon boolean operations in CSG manner, see [method merge_polygons_2d], [method clip_polygons_2d], [method intersect_polygons_2d], [method exclude_polygons_2d]. + </description> + </method> <method name="triangulate_polygon"> <return type="PoolIntArray"> </return> @@ -315,5 +439,41 @@ </method> </methods> <constants> + <constant name="OPERATION_UNION" value="0" enum="PolyBooleanOperation"> + Create regions where either subject or clip polygons (or both) are filled. + </constant> + <constant name="OPERATION_DIFFERENCE" value="1" enum="PolyBooleanOperation"> + Create regions where subject polygons are filled except where clip polygons are filled. + </constant> + <constant name="OPERATION_INTERSECTION" value="2" enum="PolyBooleanOperation"> + Create regions where both subject and clip polygons are filled. + </constant> + <constant name="OPERATION_XOR" value="3" enum="PolyBooleanOperation"> + Create regions where either subject or clip polygons are filled but not where both are filled. + </constant> + <constant name="JOIN_SQUARE" value="0" enum="PolyJoinType"> + Squaring is applied uniformally at all convex edge joins at [code]1 * delta[/code]. + </constant> + <constant name="JOIN_ROUND" value="1" enum="PolyJoinType"> + While flattened paths can never perfectly trace an arc, they are approximated by a series of arc chords. + </constant> + <constant name="JOIN_MITER" value="2" enum="PolyJoinType"> + There's a necessary limit to mitered joins since offsetting edges that join at very acute angles will produce excessively long and narrow 'spikes'. For any given edge join, when miter offsetting would exceed that maximum distance, 'square' joining is applied. + </constant> + <constant name="END_POLYGON" value="0" enum="PolyEndType"> + Endpoints are joined using the [enum PolyJoinType] value and the path filled as a polygon. + </constant> + <constant name="END_JOINED" value="1" enum="PolyEndType"> + Endpoints are joined using the [enum PolyJoinType] value and the path filled as a polyline. + </constant> + <constant name="END_BUTT" value="2" enum="PolyEndType"> + Endpoints are squared off with no extension. + </constant> + <constant name="END_SQUARE" value="3" enum="PolyEndType"> + Endpoints are squared off and extended by [code]delta[/code] units. + </constant> + <constant name="END_ROUND" value="4" enum="PolyEndType"> + Endpoints are rounded off and extended by [code]delta[/code] units. + </constant> </constants> </class> |