package spacesettlers.utilities;

/**
 * Position in space (x,y,orientation)
 * @author amy
 *
 */
public class Position {
	double x, y, orientation, angularVelocity;
	Vector2D velocity;

	public Position(double x, double y) {
		super();
		this.x = x;
		this.y = y;
		velocity = new Vector2D();
	}

	public Position(double x, double y, double orientation) {
		super();
		this.x = x;
		this.y = y;
		this.orientation = orientation;
		velocity = new Vector2D();
	}
	
	public Position(Vector2D vec) {
		super();
		this.x = vec.getXValue();
		this.y = vec.getYValue();
		orientation = 0;
		velocity = new Vector2D();
	}
	
	public Position deepCopy() {
		Position newPosition = new Position(x, y, orientation);
		newPosition.velocity = new Vector2D(velocity);
		newPosition.angularVelocity = angularVelocity;
		
		return newPosition;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	public double getOrientation() {
		return orientation;
	}
	
	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public double getTotalTranslationalVelocity() {
		return velocity.getTotal();
	}
	
	public double getTranslationalVelocityX() {
		return velocity.getXValue();
	}
	
	public double getTranslationalVelocityY() {
		return velocity.getYValue();
	}
	
	public Vector2D getTranslationalVelocity() {
		return velocity;
	}
	
	public void setTranslationalVelocity(Vector2D newVel) {
		this.velocity = newVel;
	}
	
	public double getAngularVelocity() {
		return angularVelocity;
	}
	
	public void setOrientation(double orientation) {
		this.orientation = orientation;
	}
	
	public double getxVelocity() {
		return velocity.getXValue();
	}

	public double getyVelocity() {
		return velocity.getYValue();
	}

	public void setAngularVelocity(double angularVelocity) {
		this.angularVelocity = angularVelocity;
	}

	public String toString() {
		String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity;
		return str;
	}
	
	/**
	 * Compares positions on location (x,y) only and ignores orientation and velocities
	 * 
	 * @param newPosition
	 * @return
	 */
	public boolean equalsLocationOnly(Position newPosition) {
		if (newPosition.getX() == x && newPosition.getY() == y) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Verifies that all components of the position are finite and not NaN
	 * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise 
	 */
	public boolean isValid() {
		if (Double.isFinite(x) && Double.isFinite(y) && 
				Double.isFinite(angularVelocity) && Double.isFinite(orientation)  &&
				velocity.isValid()) {
			return true;
		} else {
			return false;
		}
	}
	
}
@@ -27,16 +27,67 @@
 ities;%0A%0A
+import spacesettlers.simulator.Toroidal2DPhysics;%0A%0A
 /**%0A * P
@@ -2801,9 +2801,810 @@
 %09%7D%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Compares positions on location (x,y) with comparing distance between two locations and ignores orientation and velocities%0A%09 * For example, it can be used to check if ship's location matches up with the position passed.%0A%09 * @param Toroidal2DPhysics object: space%0A%09 * @param Position object: shipPosition%0A%09 * @param Position object: currentPosition%0A%09 * @return true if ship reached certain location or within the allowable difference distance i.e., between 0 and 4.%0A%09 */%0A%09public boolean equalsLocationOnlyWithDistance(Toroidal2DPhysics space, Position shipPosition, Position currentPosition) %7B%0A%09%09double differenceDistance = space.findShortestDistance(shipPosition, currentPosition);%0A%09%09if (differenceDistance %3E 0 && differenceDistance %3C 4) %7B%0A%09%09%09return true;%0A%09%09%7D else %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %7D

Developed new method called: equalsLocationOnlyWithDistance