It's part of a software application, but should be irrelevant for this. The main thing is the code generates a set of rectangles (with each having x, y position and width, height).
Some rectangles are inside other bigger ones.
What I need to do is to calculate the whitespace between them (for example, if two rectangles are separated, the whitespace is the distance between them, but if a rectangle is inside of another, then the whitespace is the space around that inside rectangle).
Is there any simple way of accomplishing this?
EDIT: here is a picture of what I need to do https://i.stack.imgur.com/w3VGN.jpg
Thank you