import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence;

public class Position {

	public Position(final double x, final double y) {
		super();
		this.x = x;
		this.y = y;
	}

	public Position() {
		super();
	}

	public double x;
	public double y;

	/**
	 * Helper to change both values x and y of this Position using one same
	 * service call
	 * 
	 * @param dx
	 * @param dy
	 */
	public void addTo_xy(double dx, double dy) {
		x += dx;
		y += dy;
	}

	/**
	 * Getter pour x
	 * 
	 * @return the x value
	 */
	public double getX() {
		return x;
	}

	/**
	 * Setter pour x
	 * 
	 * @param x
	 *            The new x value
	 */
	public void setX(double x) {
		this.x = x;
	}

	/**
	 * Getter pour y
	 * 
	 * @return the y value
	 */
	public double getY() {
		return y;
	}

	/**
	 * Setter pour y
	 * 
	 * @param y
	 *            The new y value
	 */
	public void setY(double y) {
		this.y = y;
	}

	public Geometry asGeometry() {
		Coordinate[] coord = { new Coordinate(this.x, this.y) };
		CoordinateArraySequence cas = new CoordinateArraySequence(coord);
		return new Point(cas, new GeometryFactory());
	}

	
	/**
	 * Returns the distance between this Position and a Polyline
	 * @param line
	 * @return a double value representing the smallest distance
	 */
	public double distToLine(Polyline line) {
		return asGeometry().distance(line.asGeometry());
	}

	/**
	 * Returns the distance between this Position and another Position
	 * @param line
	 * @return a double value representing the smallest distance
	 */
	public double distToPos(Position otherPos) {
		return asGeometry().distance(otherPos.asGeometry());
	}

	
}
