How can fill the holes in self-intersecting polygon ?

Godot Version

v4.6.2.stable.official [71f334935]

Question

I am making a tower defense game and I wanted to make a polygon shape collider which automatically generates taking the same shape as the enemies’ path but larger.

I made that by adding on either side of the path, two points for each point in the curve.

I like the result but unsurprisingly it creates some holes (like in the first bend starting from the right).

How can I make it into a solid shape with no holes ? Basically generating a new polygon only using the outer part of the polygon.

I have tried using Geometry.merge() to take advantage the EVEN ODD fill rule as mentioned here

I also tried finding the intersections and after some tinkering I am still not sure how to use that information.

Here is the code for the collider :

func _ready() -> void:
    var curve = enemy_path.curve.tessellate()
	var direction_of_next_point : Vector2
	var collider_shape : PackedVector2Array
	collider_shape.resize(curve.size() * 2)
    
	for point in curve.size():
		if not point == curve.size() - 1:
			direction_of_next_point = Vector2.from_angle(curve[point].angle_to_point(curve[point + 1]))
		
		collider_shape[point] = Vector2.ZERO
        collider_shape[-(point + 1)] = Vector2.ZERO

		collider_shape[point].x = (
				curve[point].x +
				Vector2(direction_of_next_point.rotated(PI / 2)
				* path_width).x
				)

		collider_shape[point].y = (
				curve[point].y +
				Vector2(direction_of_next_point.rotated(PI / 2)
				* path_width).y
				)

		
		collider_shape[-(point + 1)].x = (
				curve[point].x + 
				Vector2(direction_of_next_point.rotated(-PI / 2)
				* path_width).x
				)

		collider_shape[-(point + 1)].y = (
				curve[point].y + 
				Vector2(direction_of_next_point.rotated(-PI / 2)
				* path_width).y
				)

You’ll have to algorithmically trim the overlaps.

How cab I do that ?

Find consecutive pairs of segment intersections and remove all segments between them.