
using System;
using Math2D;

namespace Math2D.Shapes
{
	
	
	public abstract class Shape2D
	{
		public Shape2D()
		{
		}
		
				
		public static Vector2D PointToPoint(Vector2D a, Vector2D b) {
			return b - a;
		}
		
		public static Vector2D PointToLine(Vector2D a, Vector2D l1, Vector2D l2) {
			Vector2D res = null;
			
			double llen = PointToPoint(l1, l2).Length;
			double x = a.X - l2.X;
			double y = a.Y - l2.Y;
			double x1 = l1.X - l2.X;
			double y1 = l1.Y - l2.Y;
			double pa = Math.Atan2(y, x);
			double la = Math.Atan2(y1, x1);
			double plen = Math.Sqrt(x*x + y*y);
			double x_ = Math.Cos(pa-la) * plen;
			double y_ = -Math.Sin(pa-la) * plen;
			
			if (x_< 0) res = l2 - a; else
				if (x_ > llen) res = l1 - a; else {
					res = new Vector2D(
				                   (float)(-Math.Sin(la) * y_),
				                   (float)(Math.Cos(la) * y_));
			}
			return res;
		}		
		
		public static float DotProduct(Vector2D p, Vector2D q) {
		  return (p.X * q.X + p.Y * q.Y);
		}		
		
		public virtual bool CheckXY(float x, float y) {
			return false;	
		}
		public abstract bool CollisionTest(Shape2D s, out Vector2D v);
		public abstract void Move(Vector2D v);
		public abstract void Offset(Vector2D v);
	}
}
