Browse Source

Remove Epsilon equality checking since the animations

dont require such precision.
pull/1793/head
Jumar Macato 8 years ago
parent
commit
45ca6af21c
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 4
      src/Avalonia.Animation/AnimationsEngine`1.cs
  2. 8
      src/Avalonia.Animation/Animator`1.cs
  3. 16
      src/Avalonia.Animation/Utils/DoubleUtils.cs
  4. 2
      src/Avalonia.Animation/Utils/EasingUtils.cs

4
src/Avalonia.Animation/AnimationsEngine`1.cs

@ -39,10 +39,10 @@ namespace Avalonia.Animation
public AnimationsEngine(Animation animation, Animatable control, Animator<T> animator, Action OnComplete, Func<double, T, T> Interpolator)
{
if (animation.SpeedRatio <= 0 || DoubleUtils.AboutEqual(animation.SpeedRatio, 0))
if (animation.SpeedRatio <= 0)
throw new InvalidOperationException("Speed ratio cannot be negative or zero.");
if (animation.Duration.TotalSeconds <= 0 || DoubleUtils.AboutEqual(animation.Duration.TotalSeconds, 0))
if (animation.Duration.TotalSeconds <= 0)
throw new InvalidOperationException("Duration cannot be negative or zero.");
_parent = animator;

8
src/Avalonia.Animation/Animator`1.cs

@ -59,12 +59,12 @@ namespace Avalonia.Animation
int kvCount = _convertedKeyframes.Count;
if (kvCount > 2)
{
if (DoubleUtils.AboutEqual(t, 0.0) || t < 0.0)
if (t <= 0.0)
{
firstCue = _convertedKeyframes[0];
lastCue = _convertedKeyframes[1];
}
else if (DoubleUtils.AboutEqual(t, 1.0) || t > 1.0)
else if (t >= 1.0)
{
firstCue = _convertedKeyframes[_convertedKeyframes.Count - 2];
lastCue = _convertedKeyframes[_convertedKeyframes.Count - 1];
@ -143,11 +143,11 @@ namespace Avalonia.Animation
// Check if there's start and end keyframes.
foreach (var frame in _convertedKeyframes)
{
if (DoubleUtils.AboutEqual(frame.Cue.CueValue, 0.0))
if (frame.Cue.CueValue == 0.0d)
{
hasStartKey = true;
}
else if (DoubleUtils.AboutEqual(frame.Cue.CueValue, 1.0))
else if (frame.Cue.CueValue == 1.0d)
{
hasEndKey = true;
}

16
src/Avalonia.Animation/Utils/DoubleUtils.cs

@ -1,16 +0,0 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
namespace Avalonia.Animation.Utils
{
internal static class DoubleUtils
{
internal static bool AboutEqual(double x, double y)
{
double epsilon = Math.Max(Math.Abs(x), Math.Abs(y)) * 1E-15;
return Math.Abs(x - y) <= epsilon;
}
}
}

2
src/Avalonia.Animation/Utils/EasingUtils.cs

@ -13,6 +13,6 @@ namespace Avalonia.Animation.Utils
/// <summary>
/// Half of <see cref="Math.PI"/>
/// </summary>
internal static double HALFPI = Math.PI / 2d;
internal const double HALFPI = Math.PI / 2d;
}
}

Loading…
Cancel
Save