# How to identify the final set of “contours” when combining multiple primitive contours

This problem is in relation to how fonts work. Say you have a "glyph" that is composed of of these 5 "contours", or enclosed loops.

On their own, each of them is a unified whole. The easiest thing we could possibly do is just blend/merge them all into one big mass, and take the outer edge to be the "new contour".

But instead I am looking at it different, and getting confused along the way.

Say that each contour was laid down one at a time, in this order:

1. black
2. pink
3. blue
4. green
5. yellow

So we start with the black and look at it as a whole.

Now we lay the pink one over the black one, but it clips or masks the black one underneath. That is, like a cookie cutter. There are two options:

1. The pink is completely a cookie cutter and has no "solid" surface.
2. Or, only the part of the pink that overlaps with the black is a cookie cutter, removing both the pink and the black, but leaving the rest of the pink and black available.

Just going to go with that.

That leaves with this:

Not too bad, visibly we have 2 complete isolated contours.

Now we add the blue, but this time it isn't cookie cutter, it just goes on top. But the end result is it isolates two parts of the black now.

Next is green. There are two major cases I want to handle. One is this, where it just cookie cuts the pink, but overlays on the rest of them.

This leaves the green with a big hole in the center.

If instead of that, it took a different path, it ends up with a white space in side of it. To get there, it passes through the pink, overlays the blue, and cookie cuts the black.

Actually on the right there's white too, and it touches the boundary of the other colored contours. So not sure about that. But in this case, the green no longer completely surrounds the pink, it shares a border with this, so hmm, maybe it does still technically engulf the whole contour.

Finally there's yellow. Yellow gets split by green so there's two isolated yellows.

So what we've just described here is a bunch of state changes to the system. We have all the basic data of the points and curves that defined the original shapes let's say.

Essentially what I'm confused about is how to determine, at this final state, what all the boundaries are. This have been split and cookie cut and overlayed and such, I am having a hard time seeing how you can go from the simple initial state of the pure original contours, to this final state of many contours with unknown properties.

For example, the white spot in the middle of the green one, I am wondering if this would be considered a nested contour of some sort. Or when the pink was covered by the green, if that means that there is a nested contour.

Essentially my question is how to iterate through the final data structure to get a list of all the resulting contours. I don't even know what the final data structure is. I know the initial one was a set of contours defined by a set of points. But when these transformation/splitting/merging operations occur, I am not sure if I should rebuild a complete list of all contours given this next step, or if it's better/easier to wait until the final state, and you can ignore all the intermediate processing steps.

Any help clarifying this problem and how to get the final list of contours (and potentially nested contours) would be very helpful.

I would also like to handle if these objects were dynamically moving, making it more than static.