public void Bake_Keyframes_IsAccurateInBetweenKeys()
            {
                var frames = new Keyframe[]
                {
                    new Keyframe(0, 0),
                    new Keyframe(1, 1),
                    new Keyframe(2, 2),
                    new Keyframe(3, 3),
                    new Keyframe(4, 4),
                    new Keyframe(5, 5)
                };

                var newFrames = new Keyframe[6];

                frames.CopyTo(newFrames, 0);

                AnimationCurveBake.Bake(ref newFrames, 30);
                int index1 = 0;
                int index2 = 0;

                float deltaTime = 5 / 900;

                for (int i = 0; i < 900; i++)
                {
                    float actual   = KeyframeUtilities.Evaluate(i * deltaTime, ref index1, newFrames);
                    float expected = KeyframeUtilities.Evaluate(i * deltaTime, ref index2, frames);
                    Assert.AreEqual(expected, actual);
                }
            }
    static public float ReduceWithMaximumAbsoluteError(ref Keyframe[] keyframes, float maxError)
    {
        int   numKeys         = keyframes.Length;
        var   newKeyFrames    = new List <Keyframe>(numKeys);
        int   prevKeyIndex    = 0;
        int   currentKeyIndex = 1;
        int   nextKeyIndex    = 2;
        float conversionError = 0.0f;

        newKeyFrames.Add(keyframes[0]);
        while (nextKeyIndex < (numKeys))
        {
            Keyframe prev = keyframes[prevKeyIndex];
            Keyframe next = keyframes[nextKeyIndex];

            for (int i = currentKeyIndex; i > prevKeyIndex; i--)
            {
                Keyframe test  = keyframes[i];
                float    value = KeyframeUtilities.Evaluate(test.time, prev, next);
                float    error = math.abs(value - test.value);
                if (error >= maxError)
                {
                    newKeyFrames.Add(keyframes[currentKeyIndex]);
                    prevKeyIndex = currentKeyIndex;
                }
            }

            currentKeyIndex++;
            nextKeyIndex++;
        }
        newKeyFrames.Add(keyframes[numKeys - 1]);

        keyframes = newKeyFrames.ToArray();
        return(conversionError);
    }
            public void Bake_Keyframes_IsAccurateOnBakedKeys()
            {
                var frames = new Keyframe[]
                {
                    new Keyframe(0, 0),
                    new Keyframe(1, 1),
                    new Keyframe(2, 2),
                    new Keyframe(3, 3),
                    new Keyframe(4, 4),
                    new Keyframe(5, 5)
                };

                var newFrames = new Keyframe[6];

                frames.CopyTo(newFrames, 0);

                AnimationCurveBake.Bake(ref newFrames, 30);
                int seekIndex = 0;

                for (int i = 0; i < newFrames.Length; i++)
                {
                    float actual   = KeyframeUtilities.Evaluate(newFrames[i].time, ref i, newFrames);
                    float expected = KeyframeUtilities.Evaluate(newFrames[i].time, ref seekIndex, frames);
                    Assert.AreEqual(expected, actual, 0.000001f);
                }
            }