public Rectangle intersection ( Rectangle other ) { int left = Math . max ( this . left , other . left ) ; int top = Math . max ( this . top , other . top ) ; int right = Math . min ( this . right , other . right ) ; int bottom = Math . min ( this . bottom , other . bottom ) ; if ( right >= left && bottom >= top ) { int height = bottom - top ; int width = right - left ; return new Rectangle ( top , left , bottom , right , width , height ) ; } else { return null ; } }
Returns the intersection with the other rectangle or null if the two rectangles do not intersect .