Skip to content

Add polygon boolean methods operating on multiple paths

Supersedes #29881. Closes #29784.

Two methods were added to unify all polypaths operations:

  • polygons_boolean_2d
  • polylines_boolean_2d

Compared to existing methods which act per operation (merge_polygons/clip_polygons etc), these can be used as general-purpose methods. These accept PolyBooleanOperation and a list of both subject and clip polygons/polylines. Compared to #29881 implementation, this doesn't do any hacks with Variants, and requires less code changes, and makes the documentation much clear.

To reiterate, the PR's implementation was inspired by #35676 from which we see that passing single polygons is not enough, as all these boolean methods may return multiple polygons comprising both from outer and inner polygons which basically can describe any type of 2D object geometrically, so being able to pass a list of polygons is required in such cases. Also see my next PR which can make use of this later on: #35706.

I think it's reasonable to keep dedicated methods per operation (merge_polygons/clip_polygons etc) because they are much easier to find in the documentation and are more or less intuitive to use.

A fairly common request I've noticed is being able to simply merge a list of polygons, so this can be achieved like this now (CC @torshid, https://github.com/godotengine/godot/pull/29881#issuecomment-526926079):

var polygons = [] # PoolVector2Array's
var solution = Geometry.polygons_boolean_2d(Geometry.OPERATION_UNION, polygons) # third argument is optional for UNION

and any other type of operation of course. This is where PolyBooleanOperation actually becomes useful.

Test project

geometry-clipper-array.zip

Merge request reports

Loading