From 646f983228d6553e322548f5c45e04e8ba4118e7 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Thu, 26 Sep 2019 21:05:30 +0800 Subject: [PATCH] Update GeometryAnimation.cs --- .../Media/Animation/GeometryAnimation.cs | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs b/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs index 85c818e4..7446d679 100644 --- a/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs +++ b/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs @@ -20,10 +20,6 @@ namespace HandyControl.Media.Animation private double[] _numbersAccumulator; - private double[][] _keyValues; - - private bool _isAnimationFunctionValid; - public GeometryAnimation() { @@ -99,11 +95,26 @@ namespace HandyControl.Media.Animation protected override Geometry GetCurrentValueCore(Geometry defaultOriginValue, Geometry defaultDestinationValue, AnimationClock animationClock) { - if (!_isAnimationFunctionValid) + if (_numbersAccumulator == null) { - ValidateAnimationFunction(); + if (_numbersFrom == null) + { + var geometryStr = defaultOriginValue.ToString(); + DecomposeValue(geometryStr, out _numbersFrom); + } + + if (_numbersTo == null) + { + var geometryStr = defaultDestinationValue.ToString(); + DecomposeValue(geometryStr, out _numbersTo); + _strings = Regex.Split(geometryStr, Rgx); + } + + UpdateValue(); } + if (_numbersAccumulator == null) return defaultOriginValue; + var progress = animationClock.CurrentProgress.Value; var easingFunction = EasingFunction; @@ -113,16 +124,7 @@ namespace HandyControl.Media.Animation } var accumulated = new double[_numbersAccumulator.Length]; - var foundation = new double[_numbersAccumulator.Length]; - - var from = _keyValues[0]; - - if (IsAdditive) - { - foundation = new double[_numbersAccumulator.Length]; - } - - + if (IsCumulative) { var currentRepeat = (double)(animationClock.CurrentIteration - 1); @@ -141,23 +143,12 @@ namespace HandyControl.Media.Animation for (var i = 0; i < _numbersAccumulator.Length; i++) { - numbers[i] = foundation[i] + accumulated[i] + from[i] + _numbersAccumulator[i] * progress; + numbers[i] = accumulated[i] + _numbersFrom[i] + _numbersAccumulator[i] * progress; } return ConvertToGeometry(numbers); } - private void ValidateAnimationFunction() - { - _keyValues = null; - - _keyValues = new double[2][]; - _keyValues[0] = _numbersFrom; - _keyValues[1] = _numbersTo; - - _isAnimationFunctionValid = true; - } - public static readonly DependencyProperty FromProperty = DependencyProperty.Register( "From", typeof(Geometry), typeof(GeometryAnimation), new PropertyMetadata(default(Geometry), OnFromChanged)); @@ -207,12 +198,6 @@ namespace HandyControl.Media.Animation set => SetValue(EasingFunctionProperty, value); } - public bool IsAdditive - { - get => (bool)GetValue(IsAdditiveProperty); - set => SetValue(IsAdditiveProperty, value); - } - public bool IsCumulative { get => (bool)GetValue(IsCumulativeProperty);