Create polygons with holes from lists of points

I’m working on a script to trace the alpha channel of an image, and turn it into a polygon. I’m using openCV to do the tracing, which works nicely, and it’s at the point where it can trace the outline of an image but I’m stuck at the point where I want it to cut any interior holes into the outer shape.

The polygons come from openCV as a list of lists of points, where each list of points is a closed contour defining the edge of the transparent alpha channel. Say it was a top-down picture of a donut, there would be two lists of points: the first list of points would describe the outer circumference, and the second list the inner circumference. I realise that somewhere on the outer polygon there will need to be a couple of edges that connect to the inner polygon, in order for it to be topologically valid as a mesh.

I could create two objects and use a boolean modifier, but because they are flat planes that doesn’t seem to work too well.

I thought about finding the closest pairs of points on the inner and outer shapes, but that doesn’t always work, as you can hopefully see in the diagram below. It quickly gets into the weeds of topology that’s well beyond my intelectual pay grade. But it feels like the sort of thing that some clever Maths person would have worked out in the nineteenth century, I know that there’s a non-zero winding algorithm for filling shapes with overlapping lines, but that isn’t applicable here, as the lines don’t ever overlap.

Is there a way of making holes in a planar polygon?

Very short answer for polygons: no.

…planar curves can do this…

oooh, nice. I’ll give that a look.