package geom 
{
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author RedMaster
	 */
	public class Vector2D 
	{
		protected var _start:Point;
		protected var _end:Point;
		protected var _angleRad:Number = 0;
		
		/**
		 * Simple 2D vector
		 * @param	start Start point of vector
		 * @param	end End point of vector
		 */
		public function Vector2D(start:Point = null, end:Point = null) 
		{
			_start = start;
			_end = end;
			if(start && end) _angleRad = Math.atan2(_end.y - _start.y, _end.x - _start.x);
		}
		
		/**
		 * Returns angle between end and start in radians
		 */
		public function get angleRadians():Number
		{
			return _angleRad;
		}
		/**
		 * Returns angle between end and start in degrees
		 */
		public function get angleDegrees():Number
		{
			return Utils.degrees(angleRadians);
		}
		/**
		 * Multiplies length of vector and recalculates end point
		 * @param	multiplier Multiplier
		 */
		public function multiplyLength(multiplier:Number):void
		{
			_end.x = (1 - multiplier) * _start.x + multiplier * _end.x;
			_end.y = (1 - multiplier) * _start.y + multiplier * _end.y;
		}
		public function get length():Number
		{
			var delta:Point = new Point(end.x - start.x, end.y - start.y);
			return Math.sqrt(delta.x * delta.x + delta.y * delta.y);
		}
		/**
		 * Start point of vector
		 */
		public function get start():Point
		{
			return _start;
		}
		public function set start(value:Point):void
		{
			_start = value;
			if(start && end) _angleRad = Math.atan2(_end.y - _start.y, _end.x - _start.x);
		}
		/**
		 * End point of vector
		 */
		public function get end():Point
		{
			return _end;
		}
		public function set end(value:Point):void
		{
			_end = value;
			if(start && end) _angleRad = Math.atan2(_end.y - _start.y, _end.x - _start.x);
		}
	}

}