/**
 * An abstraction of a point -- a location with an x- and y-coordinate
 *
 * @author Prof. William Killian
 * @date   April 23, 2018
 * 
 */
public class Point {

  // The fields (representing the state) are usually declared at the
  // bottom, but we will list them up top
  //////////////////////////////////////////////////////////////////

  /**
   * x location member field
   */
  public int x;

  /**
   * y location member field
   */
  public int y;

  // Constructors are usually at the top of the class definition
  //////////////////////////////////////////////////////////////////
  
  /**
   * Default constructor -- sets location to the origin
   */
  public Point () {
    setLocation (0, 0);
  }
  
  /**
   * Constructor which sets location to passed x and y coordinate
   *
   * @param x the x location of the point
   * @param y the y location of the point
   */
  public Point (int x, int y) {
    setLocation (x, y);
  }
  
  // Behavior methods follow the constructors
  // Here mutators are listed before accessors
  //////////////////////////////////////////////////////////////////

  /**
   * Sets the location of the Point to a new x and y
   *
   * @param x the new x location for the point
   * @param y the new y location for the point
   */
  public void setLocation (int x, int y) {
    this.x = x;
    this.y = y;
  }

  /**
   * Changes the location of the Point by a passed delta x and delta y
   *
   * @param dx the change to be made for the x-direction
   * @param dy the change to be made for the y-direction
   */
  public void translate (int dx, int dy) {
    setLocation (x + dx, y + dy);
  } 
  
  /**
   * Computes and returns the distance between this point and another point
   *
   * @param p the other point to use for the distance measure
   *
   * @return the calculated distance between the two points
   */
  public double distance (Point p) {
    int dx = x - p.x;
    int dy = y - p.y;
    return Math.sqrt (Math.pow (dx, 2) + Math.pow (dy, 2));
  }
  
  /**
   * Compute and returns the distance between this point and the origin (0, 0)
   *
   * @return the calculated distance between this point and the origin
   */
  public double distanceFromOrigin () {
    return distance (new Point ());
  }
  
  /**
   * A convenient to string function which yields a human-readable String
   * representation of a point
   *
   * @return a string representing the Point "(x, y)"
   */
  public String toString () {
    return "(" + x + ", " + y + ")";
  }
}
