Geometry, Two Rectangles Overlapping, Sharing Boundaries, Distinct So I have this program that needs to test two rectangles and check:


*

*If the test rectangle is within the reference rectangle

*If the test rectangle is overlapping the reference rectangle

*If the test rectangle is only sharing a border with the reference rectangle

*If the test rectangle and reference rectangle are distinct


Both the reference and test rectangles are defined with their center coordinates (x,y) and their width and height.
I believe I have the first check coded correctly, but I cannot figure out the math for the last three checks of overlapping, sharing boundary, and being totally distinct.
I understand this isn't a programming site but my issue is purely math related not programming related. Whenever it says this.variable it is referring to the reference rectangle's value. r.variable is referring to the rectangle being tested against the reference rectangle.
Here is my code for the four checks so far:
   //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) {

 }

Any help is greatly appreciated, thank you!
 A: I'm not going to write all the code, but mathematically I'll try to give an idea of what to check for.
First I'll define "reach" as half the width (for the x direction) or half the height (for the y). I call it reach because that's how far the rectangle can "reach" from its center (x,y) to other parts of the plane. 
In order to check if they overlap, first check if the sum of their "reaches" (half their widths/heights) in the x direction is greater than the x-distance between them. Then do the same for the y direction and y "reach". I'm not going to write the code, but roughly:
if(w1/2+w2/2>abs(x1-x2)){
if(h1/2+h2/2>abs(y1-y2)){
return true. 
if the reaches aren't more than the distances, they don't overlap. 
If they only share a border, then one of four things could be true:


*

*The x coordinate of the first rectangle plus its reach is equal to the x coordinate of the second one minus its reach (x1+w1/2=x2-w2/2).

*The x coordinate of the second rectangle plus its reach is equal to the x coordinate of the first one minus its reach (x2+w2/2=x1-w1/2).

*The next two are the same except replace all x's with y's and all w's with h's.


The rectangles can only be totally distinct if there is no border touching and no overlap, so if all of the others return false then they must be totally distinct.
A: First of all, distinct = not contains and not overlap and not boundaries touch.
I would start by writing two method in MyRectangle2D class like this:

    boolean isPointInside(int x, int y)
    boolean isPointOnBoundary(int x, int y)
to check when the point (x, y) is inside the current rectangle or on the boundary.
Then:

public boolean contains(MyRectangle2D r){
    //all r tips are inside the current rectangle. 
    //Use isPointInside function  
}

public boolean overlaps(MyRectangle2D r) {
    //one and only one of r tips is inside the current rectangle. 
    //Use isPointInside function and contains function to check it is not contained
}

public boolean abut(MyRectangle2D r) {
    //at least one of r corners is on the current rectangle boundary. 
    //Use isPointOnBoundary function  
}
public boolean distinct(MyRectangle2D r) {
    return ! contains(r) && ! overlaps(r) & ! abut(r);
 }

