Ejemplo n.º 1
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public IPickable getPickableShapeAt(int x, int y, Class type) {
    IPickable res = null;
    int bestDist = Integer.MAX_VALUE;
    synchronized (shapes) {
      for (int i = shapes.size() - 1; i >= 0; i--) {
        Shape shape = shapes.get(i);
        if (shape.screenCoordinates != null
            && ((type == null && shape instanceof IPickable)
                || (type != null && type.isAssignableFrom(shape.getClass())))) {

          int distSq =
              (shape.screenCoordinates.x - x) * (shape.screenCoordinates.x - x)
                  + (shape.screenCoordinates.y - y) * (shape.screenCoordinates.y - y);
          if (distSq > shape.diameter * shape.diameter / 4 + 7 * 7) continue;
          distSq += shape.screenCoordinates.z;
          if (distSq < bestDist) {
            bestDist = distSq;
            res = (IPickable) shape;
          }
        }
      }
    }
    return res;
  }
Ejemplo n.º 2
0
  private void _assertIntersect(String msg, SpatialRelation expected, Shape a, Shape b) {
    SpatialRelation sect = a.relate(b);
    if (sect == expected) return;
    msg = ((msg == null) ? "" : msg + "\r") + a + " intersect " + b;
    if (expected == WITHIN || expected == CONTAINS) {
      if (a.getClass().equals(b.getClass())) // they are the same shape type
      assertEquals(msg, a, b);
      else {
        // they are effectively points or lines that are the same location
        assertTrue(msg, !a.hasArea());
        assertTrue(msg, !b.hasArea());

        Rectangle aBBox = a.getBoundingBox();
        Rectangle bBBox = b.getBoundingBox();
        if (aBBox.getHeight() == 0
            && bBBox.getHeight() == 0
            && (aBBox.getMaxY() == 90 && bBBox.getMaxY() == 90
                || aBBox.getMinY() == -90 && bBBox.getMinY() == -90)) ; // == a point at the pole
        else assertEquals(msg, aBBox, bBBox);
      }
    } else {
      assertEquals(msg, expected, sect); // always fails
    }
  }
Ejemplo n.º 3
0
 public static void rotate(Shape shape) {
   if (shape instanceof Circle) return;
   System.out.println("Rotate shape " + shape.getClass().getName());
 }