Skip to content

Add support to perform boolean operations on array of polypaths

Enhances #28987. Closes #29784.

multiple_polygons_clipping

  • orange polygons aka polygons_a aka subject;
  • blue polygons aka polygons_b aka clip;
  • green polygons are solution per boolean operation, in order: UNION, DIFFERENCE, INTERSECTION, XOR.

Changes:

  • polygon clipping is done on vector of polygons internally now.
  • bind Variant to mix and match both single polygon operations and array of polygons/polylines.
  • merging polygons requires only one parameter now.
    • NonZero filling was choosen by default to make this happen (see comment upstream).
  • did the same treatment for polygon/polyline inflating/deflating methods.
  • update docs.

Examples:

var poly_a = PoolVector2Array([Vector2(), ...])
var poly_a = PoolVector2Array([Vector2(), ...])
var poly_a = PoolVector2Array([Vector2(), ...])

# before: no total merge guaranteed
var res = Geometry.merge_polygons_2d(poly_a, poly_b)
res = Geometry.merge_polygons_2d(res[0], poly_c)

# after: merge guaranteed if all overlap
var res = Geometry.merge_polygons_2d([poly_a, poly_b, poly_c])

# Mix and match:

# `a` polygon is clipped by both `b` and `c` polygons:
var res = Geometry.clip_polygons_2d(poly_a, [poly_b, poly_c])

# `a` and `b` polygons are clipped by a single `c` polygon:
var res = Geometry.clip_polygons_2d([poly_a, poly_b], poly_c)

One could see how this kinda increased complexity a bit internally, but at the same time I've managed to reuse recurrent procedures used for binding. I also wonder how this could affect performance and interfere with static typing.

Feedback welcomed, inviting for discussion people who expressed interest in this: @Dr4kzor @avencherus, @daw11

Test project

geometry-clipper-array.zip

Merge request reports

Loading