static boolean subtract(Rectangle rect,Rectangle subtr){
  if (rect == null || subtr == null) {
    return true;
  }
  Rectangle common=rect.intersection(subtr);
  if (common.isEmpty()) {
    return true;
  }
  if (rect.x == common.x && rect.y == common.y) {
    if (rect.width == common.width) {
      rect.y+=common.height;
      rect.height-=common.height;
      return true;
    }
 else     if (rect.height == common.height) {
      rect.x+=common.width;
      rect.width-=common.width;
      return true;
    }
  }
 else   if (rect.x + rect.width == common.x + common.width && rect.y + rect.height == common.y + common.height) {
    if (rect.width == common.width) {
      rect.height-=common.height;
      return true;
    }
 else     if (rect.height == common.height) {
      rect.width-=common.width;
      return true;
    }
  }
  return false;
}

static boolean subtract ( Rectangle rect , Rectangle subtr ) { if ( rect == null || subtr == null ) { return true ; } Rectangle common = rect . intersection ( subtr ) ; if ( common . isEmpty ( ) ) { return true ; } if ( rect . x == common . x && rect . y == common . y ) { if ( rect . width == common . width ) { rect . y += common . height ; rect . height -= common . height ; return true ; } else if ( rect . height == common . height ) { rect . x += common . width ; rect . width -= common . width ; return true ; } } else if ( rect . x + rect . width == common . x + common . width && rect . y + rect . height == common . y + common . height ) { if ( rect . width == common . width ) { rect . height -= common . height ; return true ; } else if ( rect . height == common . height ) { rect . width -= common . width ; return true ; } } return false ; }
subtracts subtr from rect . if the result is rectangle changes rect and returns true . otherwise false .
