要在document/view中实现一个用鼠标捕获两个矩形,然后判断这两个矩形是否重叠,这个题目好象很常见,许多书上都有,但是小弟现在没有资料!
可以要到下列的数据结构:
struct point
{
int x;
int y;
}
struct rect
{
struct point UL, //Upper Left point
struct point LR, //Lower Right point
}
函数的原形可以这样写
int overlap(struct rect A, struct rect B)
可以要到下列的数据结构:
struct point
{
int x;
int y;
}
struct rect
{
struct point UL, //Upper Left point
struct point LR, //Lower Right point
}
函数的原形可以这样写
int overlap(struct rect A, struct rect B)
CRect::IntersectRect
BOOL IntersectRect( LPCRECT lpRect1, LPCRECT lpRect2 );Return ValueNonzero if the intersection is not empty; 0 if the intersection is empty.
有这个函数BOOL IntersectRect( LPCRECT lpRect1, LPCRECT lpRect2 );
的实现代码吗?
{
int left,right,top,bottom,res;
left=min(A.UL.x,B.UL.x);
top=min(A.UL.y,B.UL.y);
right=max(A.LR.x,B.LR.x);
bottom=max(A.LR.y,B.LR.y);
res=(right-left<A.LR.x-A.UL.x+B.LR.x-B.UL.x)&&
(bottom-top<A.LR.y-A.UL.y+B.LR.y-B.UL.y);
return res;
}
//left,right,top,bottom是包含A和B的最小矩形。
//若AB香蕉,这个矩形的长应该小于AB的长之和。这个矩形的宽应该小于AB的宽之和
timepalette(时间调色板)
如果我要得到相交的矩形的两个点的坐标,UL,LR,
考虑一下又有多少呢?