I have a collection of rectangles, and a reference rectangle. I want to find out if the reference rectangle is completely obscured by the rectangles above it (all of those in the collection). For example :
The obvious solution is to create a matrix of bools or a bitmap and simply blit all the rectangles and check if there's anything that isn't covered, but that's not an option. This would have to be done lots of times per second.
I came up with this idea : for every rectangle, intersect it with every other rectangle (and limit them to the reference rectangle), resulting in a collection of smaller rectangles that don't intersect, like this :
Then simply add all their areas and subtract from the area of the reference rectangle. However I'm not sure exactly how to do this best. Any other ideas, suggestions or examples are welcome.
Thank you.