# 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<Point>()

func contains(_ point: Point) -> 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:

1. Users taps.
2. Get point.
3. Find the region that contains that point.
4. 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.