public void TestFitting() { // Make a sinus between T = 0s to 10s at 60 FPS var animationChannel = new AnimationChannel(); animationChannel.KeyFrames.Add(new KeyFrameData <float> { Time = CompressedTimeSpan.Zero, Value = 0.0f }); animationChannel.KeyFrames.Add(new KeyFrameData <float> { Time = CompressedTimeSpan.FromSeconds(10.0), Value = 0.0f }); var maxErrorThreshold = 0.05f; var timeStep = CompressedTimeSpan.FromSeconds(1.0f / 60.0f); Func <CompressedTimeSpan, float> curve = x => { if (x.Ticks == 196588) { } return((float)Math.Sin(x.Ticks / (double)CompressedTimeSpan.FromSeconds(10.0).Ticks *Math.PI * 2.0)); }; animationChannel.Fitting( curve, CompressedTimeSpan.FromSeconds(1.0f / 60.0f), maxErrorThreshold); var evaluator = new AnimationChannel.Evaluator(animationChannel.KeyFrames); for (var time = CompressedTimeSpan.Zero; time < CompressedTimeSpan.FromSeconds(10.0); time += timeStep) { var diff = Math.Abs(curve(time) - evaluator.Evaluate(time)); Assert.That(diff, Is.LessThanOrEqualTo(maxErrorThreshold)); } }
public void TestFitting() { // Make a sinus between T = 0s to 10s at 60 FPS var animationChannel = new AnimationChannel(); animationChannel.KeyFrames.Add(new KeyFrameData<float> { Time = CompressedTimeSpan.Zero, Value = 0.0f }); animationChannel.KeyFrames.Add(new KeyFrameData<float> { Time = CompressedTimeSpan.FromSeconds(10.0), Value = 0.0f }); var maxErrorThreshold = 0.05f; var timeStep = CompressedTimeSpan.FromSeconds(1.0f / 60.0f); Func<CompressedTimeSpan, float> curve = x => { if (x.Ticks == 196588) { } return (float)Math.Sin(x.Ticks / (double)CompressedTimeSpan.FromSeconds(10.0).Ticks * Math.PI * 2.0); }; animationChannel.Fitting( curve, CompressedTimeSpan.FromSeconds(1.0f / 60.0f), maxErrorThreshold); var evaluator = new AnimationChannel.Evaluator(animationChannel.KeyFrames); for (var time = CompressedTimeSpan.Zero; time < CompressedTimeSpan.FromSeconds(10.0); time += timeStep) { var diff = Math.Abs(curve(time) - evaluator.Evaluate(time)); Assert.That(diff, Is.LessThanOrEqualTo(maxErrorThreshold)); } }