typedef struct Rect {
int left;
int top;
int right;
int bottom;
} Rect;
int min(int a, int b) {
return (a<b) ? a : b;
}
int max(int a, int b) {
return (a>b) ? a : b;
}
bool isEmpty(const Rect* r) {
return ((r->right-r->left)<=0) || ((r->bottom-r->top)<=0);
}
bool intersect(const Rect* r1, const Rect* r2, Rect* result)
{
result->left = max(r1->left, r2->left);
result->top = max(r1->top, r2->top);
result->right = min(r1->right, r2->right);
result->bottom = min(r1->bottom, r2->bottom);
return !(isEmpty(result));
}
如何判断两个矩形是否存在交集
最新推荐文章于 2024-06-29 03:14:24 发布