package edu.wisc.cs.games10.chrononaut;



class Vector2D {
	float x;
	float y;

	Vector2D(float x_, float y_) {
		x = x_; y = y_;
	}

	public void add(Vector2D v) {
		x += v.x;
		y += v.y;
	}

	public void mult(float n) {
		x *= n;
		y *= n;
	}
	
	public float heading2D() {
		float angle = (float) Math.atan2(-y, x);
		return -1 * angle;
	}
	
	public float magnitude() {
		return (float) Math.sqrt(x * x + y * y);
	}
	
	public void limit(float max) {
		float m = magnitude();
		if (m > max) {
			mult(max / m);
		}
	}
	
	public void normalize() {
		float m = magnitude();
		if (m > 0) {
			mult(1 / m);
		}
	}
	
	public Vector2D copy() {
		return new Vector2D(x, y);
	}
	
// static functions that make copies of the vectors (do not modify input)
	public static float distance (Vector2D v1, Vector2D v2) {
		float dx = v1.x - v2.x;
		float dy = v1.y - v2.y;
		return (float) Math.sqrt(dx*dx + dy*dy);
	}

	public static float dot(Vector2D v1, Vector2D v2) {
		return v1.x * v2.x + v1.y * v2.y;
	}

	public static Vector2D add(Vector2D v1, Vector2D v2) {
		return new Vector2D(v1.x + v2.x,v1.y + v2.y);
	}

	public static Vector2D sub(Vector2D v1, Vector2D v2_) {
		Vector2D v = new Vector2D(v1.x - v2_.x, v1.y - v2_.y);
		return v;
	}

	public static Vector2D mult(Vector2D v1, float n) {
		Vector2D v = new Vector2D(v1.x*n, v1.y*n);
		return v;
	}
}
