using Microsoft.Xna.Framework;
using System;

namespace Raycast.Win32
{
    public static class GeographyHelper
    {
        private const float Plane = 2 / 3f;

        public static Orientation OrientTo(this Vector2 direction)
        {
            if (Math.Abs(direction.X) > Math.Abs(direction.Y))
            {
                return direction.X > 0
                    ? Orientation.East
                    : Orientation.West;
            }
            else
            {
                return direction.Y > 0
                    ? Orientation.South
                    : Orientation.North;
            }
        }

        public static Vector2 GetDirection(this Orientation orientation)
        {
            switch (orientation)
            {
                case Orientation.East: return new Vector2(1, 0);
                case Orientation.South: return new Vector2(0, 1);
                case Orientation.West: return new Vector2(-1, 0);
                case Orientation.North: return new Vector2(0, -1);
            }
            return Vector2.Zero;
        }

        public static Vector2 GetPlane(this Orientation orientation)
        {
            switch (orientation)
            {
                case Orientation.East: return new Vector2(0, Plane);
                case Orientation.South: return new Vector2(Plane, 0);
                case Orientation.West: return new Vector2(0, -Plane);
                case Orientation.North: return new Vector2(-Plane, 0);
            }
            return Vector2.Zero;
        }
    }

    public enum Orientation : int
    {
        East = 0,
        South = 1,
        West = 2,
        North = 3
    }
}
