using UnityEngine;

public static class Vector2Extension {

	public static Vector2 Rotate(this Vector2 v, float degrees) {
		float sin = Mathf.Sin(degrees * Mathf.Deg2Rad);
		float cos = Mathf.Cos(degrees * Mathf.Deg2Rad);

		float tx = v.x;
		float ty = v.y;
		v.x = (cos * tx) - (sin * ty);
		v.y = (sin * tx) + (cos * ty);
		return v;
	}

	public static float ToAngle(this Vector2 v) {
		if (v.y > 0) {
			return Mathf.Acos(v.normalized.x) * Mathf.Rad2Deg;
		} else {
			return (2 * Mathf.PI - Mathf.Acos(v.normalized.x)) * Mathf.Rad2Deg;
		}
	}
}