package engine 
{
	import flash.geom.Point;
	/**
	 * ...
	 * @author Fiodar Paulavets
	 * @version 1.0
	 * @since 08.02.2012
	 */
	public class MathExt 
	{
		
		public static function Distance(x1: Number, y1: Number, x2: Number, y2: Number): Number
		{
			return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
		}
		
		public static function Speed(x1: Number, y1: Number, x2: Number, y2: Number): Point
		{
			var x: Number = x2 - x1, y: Number = y2 - y1;
			var l: Number = Math.sqrt(x * x + y * y);
			if (l == 0)
				return new Point(0, 0)
			else
				return new Point(x / l, y / l);
		}
		
		public static function GetAngle(x1: Number, y1: Number, x2: Number, y2: Number, norm: Boolean = true): Number
		{
			var dx: Number = x2 - x1;
			var dy: Number = y2 - y1;
			var angle: Number = Math.atan2(dy, dx);
			
			if (norm)
			{
				if (angle < 0)
				{
					angle += Math.PI * 2;
				}
				else if (angle >= Math.PI * 2)
				{
					angle -= Math.PI * 2;
				}
			}
			
			return angle;
		}
		
	}

}