比如两个x轴方向的区间段,C语言如何快速判断两个区间段是否有交叉呢?
请看下面代码
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);
return (rcTmp.right >= rcTmp.left);
}