package CK.IA;

/**
 * An tridimensional vector, where it's precision is stored as double.
 * 
 * @author Administrator
 * 
 */
public class Vector3d extends Object {
	// allow external modification, no evil in this
	public double x, y, z;

	Vector3d(double unit) {
		this.x = unit;
		this.y = unit;
		this.z = unit;
	}

	public Vector3d(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Vector3d(Vector3d position) {
		this.x = position.x;
		this.y = position.y;
		this.z = position.z;
	}

	public void add(double x, double y, double z) {
		this.x += x;
		this.y += y;
		this.z += z;
	}

	public void add(Vector3d v) {
		this.x += v.x;
		this.y += v.y;
		this.z += v.z;
	}

	public void addX(double delta) {
		this.x += delta;
	}

	public void addXY(double delta) {
		this.addX(delta);
		this.addY(delta);
	}

	public void addXYZ(double delta) {
		this.addX(delta);
		this.addY(delta);
		this.addZ(delta);
	}

	public void addXZ(double delta) {
		this.addX(delta);
		this.addZ(delta);
	}

	public void addY(double delta) {
		this.y += delta;
	}

	public void addYZ(double delta) {
		this.addY(delta);
		this.addZ(delta);
	}

	public void addZ(double delta) {
		this.z += delta;
	}

	public Vector3d clone() {
		return new Vector3d(this);
	}

	public double distanceTo(Vector3d to) {
		double x_dif = this.x - to.x;
		double y_dif = this.y - to.y;
		double z_dif = this.z - to.z;
		return (Math.sqrt(x_dif * x_dif + y_dif * y_dif + z_dif * z_dif));
	}

	public boolean equals(Vector3d to) {
		return (to.x == this.x && to.y == this.y && to.z == this.z);
	}

	public double length() {
		return (Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z));
	}

	public void multiplyScalar(double s) {
		this.x *= s;
		this.y *= s;
		this.z *= s;
	}

	public void negate() {
		this.x = -this.x;
		this.y = -this.y;
		this.z = -this.z;
	}

	public void nullifyX() {
		this.x = 0.0;
	}

	public void nullifyY() {
		this.y = 0.0;
	}

	public void nullifyZ() {
		this.z = 0.0;
	}

	public void subtract(Vector3d v) {
		this.x -= v.x;
		this.y -= v.y;
		this.z -= v.z;
	}

	public String toString() {
		return ("(" + x + ", " + y + ", " + z + ")");
	}

}
