Android Open Source - gti350-lab2-android-demo Point2 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;
//  www .ja v a  2  s. c  om

public class Point2D {

  public float [] p = new float[2];

  public Point2D() {
    p[0] = p[1] = 0;
  }

  public Point2D( float x, float y ) {
    p[0] = x;
    p[1] = y;
  }

  public Point2D( Point2D P ) {
    p[0] = P.p[0];
    p[1] = P.p[1];
  }

  public Point2D( Vector2D V ) {
    p[0] = V.v[0];
    p[1] = V.v[1];
  }

  public void copy( float x, float y ) {
    p[0] = x;
    p[1] = y;
  }

  public void copy( Point2D P ) {
    p[0] = P.p[0];
    p[1] = P.p[1];
  }

  public boolean equals( Point2D other ) {
    return x() == other.x() && y() == other.y();
  }

  public float x() { return p[0]; }
  public float y() { return p[1]; }

  // used to pass coordinates directly to OpenGL routines
  public float [] get() { return p; }

  // return the difference between two given points
  static public Vector2D diff( Point2D a, Point2D b ) {
    return new Vector2D( a.x()-b.x(), a.y()-b.y() );
  }

  // return the sum of the given point and vector
  static public Point2D sum( Point2D a, Vector2D b ) {
    return new Point2D( a.x()+b.x(), a.y()+b.y() );
  }

  // return the difference between the given point and vector
  static public Point2D diff( Point2D a, Vector2D b ) {
    return new Point2D( a.x()-b.x(), a.y()-b.y() );
  }

  public float distance( Point2D otherPoint ) {
    return diff( this, otherPoint ).length();
  }

  static Point2D average( Point2D a, Point2D b ) {
    // return new Point2D( Vector2D.mult( Vector2D.sum( new Vector2D(a), new Vector2D(b) ), 0.5f ) );
    return new Point2D( (a.x()+b.x())*0.5f, (a.y()+b.y())*0.5f );
  }

}




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