Ejemplo n.º 1
0
  public Rectangle combineRectangles(Rectangle rect) {
    int x1, y1, x2, y2;

    x1 = Math.min(this.x1, rect.getX1());
    y1 = Math.min(this.y1, rect.getY1());
    x2 = Math.max(this.x2, rect.getX2());
    y2 = Math.max(this.y2, rect.getY2());
    return new Rectangle(x1, y1, x2, y2);
  };
Ejemplo n.º 2
0
  public Rectangle intersectionOfREctangles(Rectangle rect) {
    int x1, y1, x2, y2;

    x1 = Math.max(this.x1, rect.getX1());
    y1 = Math.max(this.y1, rect.getY1());
    x2 = Math.min(this.x2, rect.getX2());
    y2 = Math.min(this.y2, rect.getY2());

    if ((x1 > x2) || (y1 > y2)) return new Rectangle(0, 0, 0, 0);
    return new Rectangle(x1, y1, x2, y2);
  };
Ejemplo n.º 3
0
 public static boolean isCollision(Rectangle r1, Rectangle r2) {
   return !(r1.getX2() < r2.getX1()
       || r1.getX1() > r2.getX2()
       || r1.getY2() < r2.getY1()
       || r1.getY1() > r2.getY2());
 }