예제 #1
0
        public void MultipleInterpolatorTypes()
        {
            Interpolator <float>  lerpFloat  = Interpolators <float> .Linear;
            Interpolator <double> lerpDouble = Interpolators <double> .Linear;

            var floats  = new float[] { 0.0f, 1.0f };
            var doubles = new double[] { 0.0, 1.0 };

            InterpolatorSource <float> floatWindow = (i) => {
                return(ref floats[i]);
            };
            InterpolatorSource <double> doubleWindow = (i) => {
                return(ref doubles[i]);
            };

            Assert.AreEqual(
                0.5f,
                lerpFloat(floatWindow, 0, 0.5f)
                );

            Assert.AreEqual(
                0.5,
                lerpDouble(doubleWindow, 0, 0.5f)
                );
        }
예제 #2
0
 public static T Cosine(InterpolatorSource <T> data, int dataOffset, float positionInWindow)
 {
     return(_Cosine(
                data(dataOffset),
                data(dataOffset + 1),
                positionInWindow
                ));
 }
예제 #3
0
        public static T Interpolate(Interpolator <T> interpolator, T[] values, float progress)
        {
            var previousValues = _TemporaryValues;

            if (_TemporarySource == null)
            {
                _TemporarySource = TemporarySource;
            }

            try {
                _TemporaryValues    = values;
                _NumTemporaryValues = values.Length;
                return(interpolator(_TemporarySource, 0, progress));
            } finally {
                _TemporaryValues = previousValues;
            }
        }
예제 #4
0
        public static T Interpolate(Interpolator <T> interpolator, T a, T b, float progress)
        {
            if ((_TemporaryValues == null) || (_TemporaryValues.Length < 2))
            {
                _TemporaryValues = new T[2];
            }
            if (_TemporarySource == null)
            {
                _TemporarySource = TemporarySource;
            }

            _TemporaryValues[0] = a;
            _TemporaryValues[1] = b;
            _NumTemporaryValues = 2;

            return(interpolator(_TemporarySource, 0, progress));
        }
예제 #5
0
        public static T Cubic(InterpolatorSource <T> data, int dataOffset, float positionInWindow)
        {
            if (positionInWindow < 0)
            {
                var n = Math.Ceiling(Math.Abs(positionInWindow));
                positionInWindow += (float)n;
                dataOffset       -= (int)n;
            }

            T     a  = data(dataOffset - 1);
            T     b  = data(dataOffset);
            T     c  = data(dataOffset + 1);
            T     d  = data(dataOffset + 2);
            T     p  = _CubicP(a, b, c, d);
            float x2 = positionInWindow * positionInWindow;
            float x3 = positionInWindow * x2;

            return(_CubicR(a, b, c, d, p, positionInWindow, x2, x3));
        }
예제 #6
0
        public static T Hermite(InterpolatorSource <T> data, int dataOffset, float positionInWindow)
        {
            if (positionInWindow < 0)
            {
                var n = Math.Ceiling(Math.Abs(positionInWindow));
                positionInWindow += (float)n;
                dataOffset       -= (int)n;
            }

            T a = data(dataOffset);
            T u = data(dataOffset + 1);
            T d = data(dataOffset + 2);
            T v = data(dataOffset + 3);

            var tSquared = positionInWindow * positionInWindow;
            var t2       = positionInWindow * 2;
            var s        = 1 - positionInWindow;
            var s2       = s * 2;
            var sSquared = s * s;

            return(_Hermite(a, u, d, v, positionInWindow, t2, tSquared, s, s2, sSquared));
        }
예제 #7
0
 static LerpSource()
 {
     Source = (i) => {
         if (i >= 1)
         {
             return(ref Values[1]);
예제 #8
0
 public HermiteSpline()
 {
     _Interpolator       = Interpolators <T> .Hermite;
     _InterpolatorSource = GetHermiteInputForIndex;
 }
예제 #9
0
 public Curve()
 {
     DefaultInterpolator = Interpolators <T> .Default;
     _InterpolatorSource = GetValueAtIndex;
 }
예제 #10
0
 public static T Null(InterpolatorSource <T> data, int dataOffset, float positionInWindow)
 {
     return(data(dataOffset));
 }
예제 #11
0
 static LerpSource()
 {
     Source = (i) => (i >= 1) ? Values[1] : Values[0];
     Values = new T[2];
 }