Esempio n. 1
0
 public static boolean internalIntersects(Shape shape1, Shape shape2) {
   TimingInfo.CURRENT_TIMING_INFO.getCounter("GeometryUtils.intersects").record(1);
   if (shape1.intersects(shape2)) return true;
   if ((shape1 instanceof Rectangle && shape2 instanceof Circle)
       || (shape2 instanceof Rectangle && shape1 instanceof Circle)) {
     Circle c;
     Rectangle r;
     if (shape1 instanceof Circle) {
       c = (Circle) shape1;
       r = (Rectangle) shape2;
     } else {
       c = (Circle) shape2;
       r = (Rectangle) shape1;
     }
     if (r.contains(c.getCenterX(), c.getCenterY())) {
       return true;
     }
   }
   if (shape2 instanceof Line) {
     return shape1.contains(shape2);
   }
   if (shape1 instanceof Line) {
     return shape2.contains(shape1);
   }
   return false;
 }
Esempio n. 2
0
 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());
 }