using System;
using SFML.Window;

namespace YourBeatingHeart.Main.Helper
{
    public static class Vector2fExtensions
    {
        public static float DistanceSqrt(this Vector2f a, Vector2f b)
        {
            float dx = a.X - b.X;
            float dy = a.Y - b.Y;
            return dx * dx + dy * dy;
        }

        public static float Distance(this Vector2f a, Vector2f b)
        {
            return (float) Math.Sqrt(DistanceSqrt(a, b));
        }

        public static float DistanceSqrt(this Vector2f a, float x, float y)
        {
            float dx = a.X - x;
            float dy = a.Y - y;
            return dx * dx + dy * dy;
        }

        public static float Distance(this Vector2f a, float x, float y)
        {
            return (float)Math.Sqrt(DistanceSqrt(a, x, y));
        }

        public static float LengthSqrt(this Vector2f vector)
        {
            return vector.X * vector.X + vector.Y * vector.Y;
        }

        public static float Length(this Vector2f vector)
        {
            return (float) Math.Sqrt(LengthSqrt(vector));
        }

        public static Vector2f GetNormalized(this Vector2f vector)
        {
            float length = vector.Length();

            if ((length == 0) || (length == 1))
                return vector;

            return new Vector2f(vector.X / length, vector.Y / length);
        }

        /*
        public static float Normalize(this Vector2f vector)
        {
            float length = vector.Length();

            if ((length == 0) || (length == 1))
                return length;

            vector.X /= length;
            vector.Y /= length;

            return length;
        }
         */
    }
}
