public static Rectangle getNewBoundingRectangle(Shape shape) { if (shape instanceof Circle) { Circle circle = (Circle) shape; float x = circle.getCenterX(); float y = circle.getCenterY(); float r = circle.getRadius(); return new Rectangle(x - r, y - r, 2 * r, 2 * r); } if (shape instanceof Line) { Line line = (Line) shape; float x1; float x2; if (line.getX2() > line.getX1()) { x1 = line.getX1(); x2 = line.getX2(); } else { x1 = line.getX2(); x2 = line.getX1(); } float y1; float y2; if (line.getY2() > line.getY1()) { y1 = line.getY1(); y2 = line.getY2(); } else { y1 = line.getY2(); y2 = line.getY1(); } return new Rectangle( x1 - EPSILON, y1 - EPSILON, x2 - x1 + 1 + EPSILON, y2 - y1 + 1 + EPSILON); } if (shape instanceof Rectangle) { Rectangle r = (Rectangle) shape; return new Rectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } assert false; return new Rectangle(shape.getMinX(), shape.getMinY(), shape.getWidth(), shape.getHeight()); }
public static boolean lineEquals(Line l1, Line l2) { return l1.getX1() == l2.getX1() && l1.getY1() == l2.getY1() && l1.getX2() == l2.getX2() && l1.getY2() == l2.getY2(); }