using System;

namespace OctreeRendering
{
    static class MathHelper
    {
        public const float Pi = (float)Math.PI;
        public const float HalfPi = (float)(Math.PI / 2);
        public const float TwoPi = (float)(Math.PI * 2);

        public static bool AlmostEqual(double a, double b, double epsilon)
        {
            return Math.Abs(a - b) <= epsilon;
        }
        public static bool AlmostEqual(double a, double b)
        {
            return Math.Abs(a - b) <= float.Epsilon;
        }

        public static float WrapAngle(float angle)
        {
            angle = (float)Math.IEEERemainder(angle, TwoPi);
            if (angle <= -Pi)
                return angle + TwoPi;
            if (angle > Pi)
                return angle - TwoPi;
            return angle;
        }

        public static float Clamp(float value, float minimum, float maximum)
        {
            return Math.Max(Math.Min(value, maximum), minimum);
        }
        public static int Clamp(int value, int minimum, int maximum)
        {
            return Math.Max(Math.Min(value, maximum), minimum);
        }

        public static float Lerp(float from, float to, float step)
        {
            return (to - from) * step + from;
        }

        public static float Max(float a, float b, float c)
        {
            return Math.Max(Math.Max(a, b), c);
        }
        public static float Min(float a, float b, float c)
        {
            return Math.Min(Math.Min(a, b), c);
        }
    }
}
