Chapter 1 VC/MFC 怎样判断两个矩形区域是否出现交叉或重叠现
Solution 1:
CRect rect1,rect2;
...................
CRgn rgn;
rgn.CreateRectRgn(rect1.left,rect1.top,rect1.right,rect1.bottom);
if (rgn.RectInRegion(&rect2))
{
//相交
}
else
{
//不相交
}
Solution 2:
CRect::IntersectRect
Nonzero if the intersection is not empty; 0 if the intersection is empty.
Solution 3:
bool IsCross( RECT *rect1, RECT *rect2 )
{
RECT rcTmp;
rcTmp.left = _max( rect1->left, rect2->left );
rcTmp.top = _max( rect1->top, rect2->top );
rcTmp.right = _min( rect1->right, rect2->right );
rcTmp.bottom = _min( rect1->bottom, rect2->bottom );
return (rcTmp.right > rcTmp.left && rcTmp.bottom > rcTmp.top);
}
Solution 4:
可以使用CRgn类的int nResult = CombineRgn(&rectA,&rectB,RGN_AND);
如果nResult != NULLREGION那么他们就是重叠的.
Solution 5:
CRect::UnionRect
以上方案未一一验证。
参考:
http://bbs.csdn.net/topics/190139350
http://bbs.csdn.net/topics/330241157