Browse Source

Replace binary-search on keyframe selection with naive approach for now.

pull/2163/head
Jumar Macato 8 years ago
parent
commit
739309c28f
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 36
      src/Avalonia.Animation/Animators/Animator`1.cs

36
src/Avalonia.Animation/Animators/Animator`1.cs

@ -78,7 +78,7 @@ namespace Avalonia.Animation.Animators
double t0 = firstKeyframe.Cue.CueValue; double t0 = firstKeyframe.Cue.CueValue;
double t1 = lastKeyframe.Cue.CueValue; double t1 = lastKeyframe.Cue.CueValue;
double progress = (animationTime - t0) / (t1 - t0); double progress = (animationTime - t0) / (t1 - t0);
T oldValue, newValue; T oldValue, newValue;
@ -97,30 +97,11 @@ namespace Avalonia.Animation.Animators
private int FindClosestBeforeKeyFrame(double time) private int FindClosestBeforeKeyFrame(double time)
{ {
int FindClosestBeforeKeyFrame(int startIndex, int length) for (int i = 0; i < _convertedKeyframes.Count; i++)
{ if (_convertedKeyframes[i].Cue.CueValue > time)
if (length == 0 || length == 1) return i - 1;
{
return startIndex;
}
int middle = startIndex + (length / 2);
if (_convertedKeyframes[middle].Cue.CueValue < time) throw new Exception("Index time is out of keyframe time range.");
{
return FindClosestBeforeKeyFrame(middle, length - middle);
}
else if (_convertedKeyframes[middle].Cue.CueValue > time)
{
return FindClosestBeforeKeyFrame(startIndex, middle - startIndex);
}
else
{
return middle;
}
}
return FindClosestBeforeKeyFrame(0, _convertedKeyframes.Count);
} }
/// <summary> /// <summary>
@ -139,13 +120,10 @@ namespace Avalonia.Animation.Animators
} }
/// <summary> /// <summary>
/// Interpolates a value given the desired time. /// Interpolates in-between two key values given the desired progress time.
/// </summary> /// </summary>
public abstract T Interpolate(double progress, T oldValue, T newValue); public abstract T Interpolate(double progress, T oldValue, T newValue);
/// <summary>
/// Verifies, converts and sorts keyframe values according to this class's target type.
/// </summary>
private void VerifyConvertKeyFrames() private void VerifyConvertKeyFrames()
{ {
foreach (AnimatorKeyFrame keyframe in this) foreach (AnimatorKeyFrame keyframe in this)
@ -193,4 +171,4 @@ namespace Avalonia.Animation.Animators
} }
} }
} }
} }

Loading…
Cancel
Save