package primitives.geomtry;
import java.awt.Point;
/**The <code>Coordinate</code> class represents a location in a
* two-dimensional (<i>x</i>,&nbsp;<i>y</i>)as <code>double</code> value coordinate space.
* @author Dori Eldar
*/
public class Coordinate {
	/**
     * The <i>x</i> coordinate. 
     */
	public double x;
	/**
     * The <i>y</i> coordinate. 
     */
	public double y;

	 /**
     * Constructs and initializes a Coordinate at the origin 
     * (0,&nbsp;0) of the coordinate space. 
	**/
	public Coordinate(){
		move(0.0,0.0);
	}
	/**
     * Constructs and initializes a coordinate at the specified 
     * (<i>x</i>,&nbsp;<i>y</i>) location in the coordinate space. 
     * @param       x   the <i>x</i> coordinate.
     * @param       y   the <i>y</i> coordinate.
     */

	public Coordinate(double x,double y) {
		move(x,y);
	}
	/**
     * Constructs and initializes a coordinate with the same location as
     * the specified <code>Coordinate</code> object.
     * @param       coordinate a Coordinate.
	 **/

	public Coordinate(Coordinate coordinate){
		move(coordinate.x,coordinate.y);
	}
	/**
     * Constructs and initializes a coordinate with the same location as
     * the specified <code>Point</code> object.
     * @param       p a point.
     */

	public Coordinate(Point p){
		move(p.x,p.y);
	}
	/**
     * Moves this point to the specificed location in the 
     * (<i>x</i>,&nbsp;<i>y</i>) coordinate plane. This method
     * is identical with <code>setLocation(double,&nbsp;double)</code>.
     * @param       x  the <i>x</i> coordinate of the new location.
     * @param       y  the <i>y</i> coordinate of the new location.
	 **/

	public void move(double x,double y){
		this.x=x;
		this.y=y;
	}
	/**
     * Moves this coordinate to the same location as the 
     * specified <code>Coordinate</code> object
     * @param       p a coordinate.
     **/

	public void move(Coordinate p){
		x = p.x;
		y = p.y;
	}
	/**
     * Translates this coordinate, at location (<i>x</i>,&nbsp;<i>y</i>), 
     * by <code>dx</code> along the <i>x</i> axis and <code>dy</code> 
     * along the <i>y</i> axis so that it now represents the coordinate 
     * (<code>x</code>&nbsp;<code>+</code>&nbsp;<code>dx</code>, 
     * <code>y</code>&nbsp;<code>+</code>&nbsp;<code>dy</code>). 
     * @param       dx   the distance to move this point 
     *                            along the <i>x</i> axis.
     * @param       dy    the distance to move this point 
     */

	public void translate(double dx,double dy){
		move(this.x+dx,this.y+dy);
	}
	/**
     * Returns a representation of this coordinate and its location
     * in the (<i>x</i>,&nbsp;<i>y</i>) coordinate space as a Point object.
	 * the (<i>x</i>,&nbsp;<i>y</i>) are rounded to the nearest integer values.
	 * @return    a Point representation of this Coordinate, 
     **/

	public ExtPoint toPoint(){
		return (new ExtPoint((int)Math.rint(x),(int)Math.rint (y)));
	}
}
