如果测试矩形为参考矩形
如果测试矩形内被重叠的基准矩形
如果测试矩形仅与参考矩形
IF测试矩形和参考矩形是不同的共享边界
参考矩形和测试矩形都以其中心坐标(x,y)及其宽度和高度定义。
我相信我有正确的第一个检查编码,但我无法弄清楚重叠,共享边界和完全不同的最后三个检查的数学。
这里是我的四个检查,到目前为止的代码:
//returns true if the specified rectangle is inside this rectangle
public boolean contains(MyRectangle2D r){
if(this.x > r.x + r.width && x + width < r.x && y > r.y +r.height && y + height < r.y){
return true;
}
else{
return false;
}
}
//returns true if the specified rectangle overlaps with this rectangle
public boolean overlaps(MyRectangle2D r) {
if (this.x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y){
return true;
}
else{
return false;
}
}
//returns true if only the boundaries touch
public boolean abut(MyRectangle2D r) {
if(this.x = r.x + r.width && x + width = r.x || y = r.y +r.height && y + height = r.y){
return true;
}
else{
return false;
}
}
//returns true if the rectangles are not touching at all
public boolean distinct(MyRectangle2D r) {
}
2016-08-06
S Zapata