using System;

public class Velocity 
{
	// Speed values expressed in pixels/millis
	// Direction expressed in radians
	
	public float vx = 0;
	public float vy = 0;
	
	public Velocity(float vx, float vy)
	{
		this.vx = vx;
		this.vy = vy;
	}
	
	public float speed => (float) Math.Sqrt(Math.Pow(vx, 2) + Math.Pow(vy, 2));
	
	public float direction => (float) (Math.Atan2(vy, vx));
	
	public void LimitSpeed(float maxSpeed)
	{
		if (speed > maxSpeed)
		{
			float dir = direction;
			
			vx = (float) Math.Cos(dir) * maxSpeed;
			vy = (float) Math.Sin(dir) * maxSpeed;
		}
	}
	
	public string ToComponentsString()
	{
		return "(" + vx + "," + vy + ")";
	}
	
	public string ToVectorString()
	{
		return "[" + speed + "," + direction + " rad]";
	}
}
