【发布时间】:2011-05-22 00:04:07
【问题描述】:
谁能告诉我我的矩形相交代码是否正确?
bool checkCollide(int x, int y, int oWidth, int oHeight,
int x2, int y2, int o2Width, int o2Height) {
bool collide = false;
if (x >= x2 && x <= x2+o2Width && y >= y2 && y <= y2+o2Height)
collide = true;
if (x+oWidth >= x2 && x+oWidth <= x2+o2Width && y >= y2 && y <= y2+o2Height)
collide = true;
if (x >= x2 && x<= x2+o2Width && y+oHeight >= y2 && y+oHeight <= y2+o2Height)
collide = true;
if (x+oWidth >= x2 && x+oWidth <= x2+o2Width && y+oHeight >= y2 && y+oHeight <= y2+o2Height)
collide = true;
return collide;
}
【问题讨论】:
-
它是否正确地与您的矩形相交?如果是这样,是的。
-
为什么不写一些单元测试代码来测试它是否为不同的输入提供了正确的答案?
-
你最好在codereview.stackexchange.com上问这个人
-
别忘了是否需要处理空矩形。
标签: c++