using System;

namespace Vortex.Tutorials.ParallaxEffect {
    static class MathHelper {
        public static float Lerp(float v1, float v2, float dt) {
            return (v2 - v1) * dt + v1;
        }

        public static float Lerp(float v1, float v2, float dt, LerpType lerpType) {
            switch (lerpType) {
                case LerpType.Default: {
                        return (v2 - v1) * dt + v1;
                    }
                case LerpType.Ease: {
                        return (float)(v1 * (2 * Math.Pow(dt, 3) - 3 * Math.Pow(dt, 2) + 1) + v2 * (3 * Math.Pow(dt, 2) - 2 * Math.Pow(dt, 3)));
                    }
                case LerpType.EaseIn: {
                        var t = 1 - dt;
                        return (float)((v2 - v1) * (Math.Sin(-t * (Math.PI / 2)) + 1) + v1);
                    }
                case LerpType.EaseOut: {
                        return (float)((v2 - v1) * -Math.Sin(-dt * (Math.PI / 2)) + v1);
                    }
                default: return (v2 - v1) * dt + v1;
            }
        }
    }

    public enum LerpType {
        Default,
        Ease,
        EaseIn,
        EaseOut
    }
}
