Ejemplo 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;
  }
Ejemplo 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;
  }
Ejemplo n.º 3
0
  public void addItem(Item item, Rect4f rect) {
    items.put(rect, item);
    itemRects.put(item, rect);

    // cause bounding box to be recomputed
    _bounding_box = null;
  }
Ejemplo n.º 4
0
 public void clear() {
   items.clear();
   itemRects.clear();
   _bounding_box = null;
 }