Microsoft Interview Question
Software Engineer / DevelopersIf the two rectangles are parameterized by the the top left corner and right bottom corner co-ordinates (with 1 pixel as 1 unit) like
1. For Rectangle R1 (r1x1, r1y1) and (r1x2, r1y2) are the respective top left corner and right bottom corner co-ordinates and
2. For Rectangle R2 (r2x1, r2y1) and (r2x2, r2y2) are the respective top left corner and right bottom corner co-ordinates then
the rectangles overlap if the following conditions are satisfied:
((r1x1 > r2x1) && (r1y1 > r2y1) && (r1x1 < r2x2) && (r1y1 < r2y2))
If the above condition is not satisfied, then the rectangles don't overlap
conditions for checking the rectangle overlap :
- Bhargava December 30, 2010Cond1. If A's left edge is to the right of the B's right edge,
- then A is Totally to right Of B
Cond2. If A's right edge is to the left of the B's left edge,
- then A is Totally to left Of B
Cond3. If A's top edge is below B's bottom edge,
- then A is Totally below B
Cond4. If A's bottom edge is above B's top edge,
- then A is Totally above B