Esempio n. 1
0
  public static Rect fromPoints(List<Point> points) {
    Rect rect = new Rect();
    double minX = Double.MAX_VALUE;
    double minY = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE;
    double maxY = Double.MIN_VALUE;

    for (Point pt : points) {
      if (pt.getX() < minX) {
        minX = pt.getX();
      }
      if (pt.getY() < minY) {
        minY = pt.getY();
      }
      if (pt.getX() > maxX) {
        maxX = pt.getX();
      }
      if (pt.getY() > maxY) {
        maxY = pt.getY();
      }
    }
    double w = maxX - minX;
    double h = maxY - minY;

    rect.set(minX, minY, w, h);
    return rect;
  }
Esempio n. 2
0
 public void copyTo(Rect rect) {
   rect.x = x;
   rect.y = y;
   rect.width = width;
   rect.height = height;
 }
Esempio n. 3
0
 public boolean contains(Rect r) {
   return contains(r.x, r.y) && contains(r.x + r.getWidth(), r.y + r.getHeight());
 }
Esempio n. 4
0
  public Rect expandIn(int w, int h, int maxW, int maxH) {
    Rect r = expand(w, h);
    if (r.getX() < 0) {
      r.setWidth(r.getWidth() + r.getX());
      r.setX(0);
    }
    if (r.getY() < 0) {
      r.setHeight(r.getHeight() + r.getY());
      r.setX(y);
    }
    if (r.getRightPos() > maxW) {
      r.setWidth(maxW - r.getX());
    }

    if (r.getBottomPos() > maxH) {
      r.setHeight(maxH - r.getY());
    }
    return r;
  }