And*_*ren 11
如果矩形r1位于x1,y1并且宽度为w1,h1,同样矩形r2位于x2,y2,宽度为w2,高度为h2,则可以找到红色区域的左边缘(假设宽度和高度为两个矩形都是正的,因此位置是左下角):
left = max(x1, x2);
同样适用于右侧,下侧和顶部:
right = min(x1 + w1, x2 + w2);
bottom = max(y1, y2);
top = min(y1 + h1, y2 + h2);
重叠区域的大小是
height = top - bottom 
width = right - left. 
如果这些是否定的,则没有重叠.