Exemplo n.º 1
0
  /** Get the rectangle which contains all other rectangles */
  public Rect4f getBoundingBox() {
    if (_bounding_box == null) {

      float left = Float.MAX_VALUE;
      float right = Float.MIN_VALUE;
      float top = Float.MIN_VALUE;
      float bottom = Float.MAX_VALUE;

      // Find maximum bounding box
      for (Rect4f rect : items.keySet()) {
        if (rect.left() < left) left = rect.left();

        if (rect.right() > right) right = rect.right();

        if (rect.bottom() < bottom) bottom = rect.bottom();

        if (rect.top() > top) top = rect.top();
      }

      // avoid MAX_VALUE and MIN_VALUE
      if (items.isEmpty()) {
        left = -0.01f;
        right = 0.01f;
        top = 0.01f;
        bottom = -0.01f;
      }

      _bounding_box = new Rect4f(left, top, right - left, top - bottom);
    }

    return _bounding_box;
  }
Exemplo n.º 2
0
  /**
   * Get the item which has a rectangle containing the given point.
   *
   * @return null if none contain the point
   */
  public Item getItemAtPos(Vec2f pos) {
    for (Rect4f rect : items.keySet()) {
      if (rect.contains(pos)) return items.get(rect);
    }

    return null;
  }