You would need some sort of flood algorithm. Check this discussion, I wrote an example that is perfect for your problem.