package bubble;

/*
 * vector are great ! they make
 * 2d programming easier.
 * Vector are simple direction
 * with magnitude, it is best
 * paired with a point object.
 * \___________________________/
 *      /
 * \ ('<                  <') /
 * (<=)                    (=>)
 *
 * how this will clean the kitchen
 * your are supposed to ?
 * \___________________________/
 *                       \
 * \ ('>                  >') /
 * (<=)                    (=>)
 *
 * not at all! but doing house
 * duty only get me to build
 * algorithm in my head.
 * \___________________________/
 *      /
 * \ ('>                  >') /
 * (<=)                    (=>)
 * */

public class Victor {
	private final double _vx,
	                     _vy;

	private Victor(double x, double y){
		_vx = x;
		_vy = y;
	}

	public static Victor fromVal(double x, double y){
		return new Victor(x,y);
	}
	private static Victor _zero = new Victor(0,0);
	public static Victor fromZero(){
		return _zero;
	}

	public double vx(){
		return _vx;
	}

	public double vy(){
		return _vy;
	}

	public double magSQ(){
		return vx()*vx() + vy()*vy();
	}

	public double mag(){
		return Math.sqrt(magSQ());
	}

	public double dot(final Victor v){
		return vx()*v.vx() + vy()*v.vy();
	}

	public double cross(final Victor v){
		return vx()*v.vy() + vy()*v.vx();
	}

	public Victor add(final Victor v){
		if (v == null)
			throw new NullPointerException();
		return new Victor(vx()+v.vx(), vy()+v.vy());
	}

	public Victor sub(final Victor v){
		if (v == null)
			throw new NullPointerException();
		return new Victor(vx()-v.vx(), vy()-v.vy());
	}

	public Victor scale(double scalar){
		return new Victor(vx()*scalar, vy()*scalar);
	}

	public Victor rot(final Victor vrot){
		return new Victor(cross(vrot),dot(vrot));
	}

	public Victor normalise(){
		return scale(1.0/mag());
	}
}
