int x2 = (int) rect.getX(); int y2 = (int) rect.getY(); int w2 = (int) rect.getWidth(); int h2 = (int) rect.getHeight();
int x2 = (int) rect.x; int y2 = (int) rect.y; int w2 = (int) rect.width; int h2 = (int) rect.height;
  public static Rectangle computeUnion(int x, int y, int w, int h,                                       Rectangle rect)  {    int x2 = (int) rect.getX();    int y2 = (int) rect.getY();    int w2 = (int) rect.getWidth();    int h2 = (int) rect.getHeight();    int dx = (x < x2) ? x : x2;    int dy = (y < y2) ? y : y2;    int dw = (x + w > x2 + w2) ? (x + w - dx) : (x2 + w2 - dx);    int dh = (y + h > y2 + h2) ? (y + h - dy) : (y2 + h2 - dy);    if (dw >= 0 && dh >= 0)      return new Rectangle(dx, dy, dw, dh);    return new Rectangle(0, 0, 0, 0);  }