Get distance between two points including size of “entities”.

--------------
| p1         |
|        p2  |
--------------


The formula to work out the difference between these two elements could be written as:

distance = ((x1-x2)(x1-x2)+(y1-y2)(y1-y2))

-----------------------
|    p1p1             |
|    p1p1             |
|                     |
|                 p2  |
-----------------------


With the above problem though, how would you get the distance if one of the points also had a size? So if p2 was "covering" p1's bounding box then the distance would be 0, and if p2 was 5 to the left or right of p1's bounding box then distance would be 5.

Would someone please show and try to explain a formula for this problem?