Android Open Source - gti350-lab2-android-demo Aligned Rectangle2 D






From Project

Back to project page gti350-lab2-android-demo.

License

The source code is released under:

MIT License

If you think the Android project gti350-lab2-android-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package log350.example.example6;
//from w ww .ja  va 2 s . c o  m
public class AlignedRectangle2D {

  public boolean isEmpty = true;
  private Point2D min = new Point2D(0,0);
  private Point2D max = new Point2D(0,0);

  public AlignedRectangle2D() {
  }
  public AlignedRectangle2D( Point2D p0, Point2D p1 ) {
    bound( p0 );
    bound( p1 );
  }

  public void clear() { isEmpty = true; }

  // Enlarge the rectangle as necessary to contain the given point
  public void bound( Point2D p ) {
    if ( isEmpty ) {
      min.copy(p);
      max.copy(p);
      isEmpty = false;
    }
    else {
      if ( p.x() < min.x() ) min.p[0] = p.x();
      else if ( p.x() > max.x() ) max.p[0] = p.x();

      if ( p.y() < min.y() ) min.p[1] = p.y();
      else if ( p.y() > max.y() ) max.p[1] = p.y();
    }
  }

  // Enlarge the rectangle as necessary to contain the given rectangle
  public void bound( AlignedRectangle2D rect ) {
    bound( rect.min );
    bound( rect.max );
  }

  public boolean isEmpty() { return isEmpty; }

  public boolean contains( Point2D p ) {
    return !isEmpty
      && min.x() <= p.x() && p.x() <= max.x()
      && min.y() <= p.y() && p.y() <= max.y();
  }
  public boolean contains( AlignedRectangle2D r ) {
    if ( isEmpty ) return false;
    if ( r.isEmpty ) return true;
    return min.x() <= r.min.x() && r.max.x() <= max.x()
      && min.y() <= r.min.y() && r.max.y() <= max.y();
  }

  public Point2D getMin() { return min; }
  public Point2D getMax() { return max; }
  public Vector2D getDiagonal() { return Point2D.diff(max,min); }
  public Point2D getCenter() {
    return Point2D.average( min, max );
  }
}




Java Source Code List

log350.example.example6.AlignedRectangle2D.java
log350.example.example6.DrawingView.java
log350.example.example6.GraphicsWrapper.java
log350.example.example6.Log350Example6Activity.java
log350.example.example6.MyButton.java
log350.example.example6.Point2DUtil.java
log350.example.example6.Point2D.java
log350.example.example6.ShapeContainer.java
log350.example.example6.Shape.java
log350.example.example6.Vector2D.java