public boolean intersects ( Shape shape ) { if ( shape instanceof Rectangle ) { Rectangle other = ( Rectangle ) shape ; if ( ( x > ( other . x + other . width ) ) || ( ( x + width ) < other . x ) ) { return false ; } if ( ( y > ( other . y + other . height ) ) || ( ( y + height ) < other . y ) ) { return false ; } return true ; } else if ( shape instanceof Circle ) { return intersects ( ( Circle ) shape ) ; } else { return super . intersects ( shape ) ; } }
Check if this box touches another