Coloring book. Finding region by point Let me explain what I want to achieve. I'm working on the coloring book project. On the input, I'm getting transparent images with black borders (Like this). Currently, I've created the 2D Matrix with colors in points. And basing on this Matrix I want to form an array of regions.
Region:
class Region {
    var set = Set&lt;Point&gt;()
    
    func contains(_ point: Point) -&gt; Bool {
        return set.contains(point)
    }
}

The region represents points that form bordered parts(e.g. gun barrel, button, hat).
My future logic will be this:

Users taps.
Get point.
Find the region that contains that point.
Color all the points in that region.

The problem is that I don't know how to form those regions :). Can you please help me solve this problem? Maybe it's some famous algorithm but I just don't know how to google it properly.
P.S. I hope this is the correct place to ask this kind of question.
Once you get the point, you can use Flood Fill Algorithm to replace the current color in the region containing the point with the new color.

Basically, this algorithm starts from a specified point and then recursively(or iteratively) keep replacing the current color with the new specified color in the neighbouring points till it reaches the boundary of the region.

It detects the boundary by checking for points having different color(different from current and new color). So you don't have detect/store the regions in advance.