|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using Avalonia.Animation.Easings; |
|
|
|
using Avalonia.Controls.Shapes; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Styling; |
|
|
|
@ -46,6 +47,22 @@ namespace Avalonia.Animation.UnitTests |
|
|
|
Assert.Throws<ArgumentException>(() => keySpline.ControlPointX2 = input); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SplineEasing_Can_Be_Mutated() |
|
|
|
{ |
|
|
|
var easing = new SplineEasing(); |
|
|
|
|
|
|
|
Assert.Equal(0, easing.Ease(0)); |
|
|
|
Assert.Equal(1, easing.Ease(1)); |
|
|
|
|
|
|
|
easing.X1 = 0.25; |
|
|
|
easing.Y1 = 0.5; |
|
|
|
easing.X2 = 0.75; |
|
|
|
easing.Y2 = 1.0; |
|
|
|
|
|
|
|
Assert.NotEqual(0.5, easing.Ease(0.5)); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
To get the test values for the KeySpline test, you can: |
|
|
|
1) Grab the WPF sample for KeySpline animations from https://github.com/microsoft/WPF-Samples/tree/master/Animation/KeySplineAnimations
|
|
|
|
@ -141,5 +158,73 @@ namespace Avalonia.Animation.UnitTests |
|
|
|
expected = 1.8016358493761722; |
|
|
|
Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Check_KeySpline_Parsing_Is_Correct() |
|
|
|
{ |
|
|
|
var keyframe1 = new KeyFrame() |
|
|
|
{ |
|
|
|
Setters = |
|
|
|
{ |
|
|
|
new Setter(RotateTransform.AngleProperty, -2.5d), |
|
|
|
}, |
|
|
|
KeyTime = TimeSpan.FromSeconds(0) |
|
|
|
}; |
|
|
|
|
|
|
|
var keyframe2 = new KeyFrame() |
|
|
|
{ |
|
|
|
Setters = |
|
|
|
{ |
|
|
|
new Setter(RotateTransform.AngleProperty, 2.5d), |
|
|
|
}, |
|
|
|
KeyTime = TimeSpan.FromSeconds(5), |
|
|
|
}; |
|
|
|
|
|
|
|
var animation = new Animation() |
|
|
|
{ |
|
|
|
Duration = TimeSpan.FromSeconds(5), |
|
|
|
Children = |
|
|
|
{ |
|
|
|
keyframe1, |
|
|
|
keyframe2 |
|
|
|
}, |
|
|
|
IterationCount = new IterationCount(5), |
|
|
|
PlaybackDirection = PlaybackDirection.Alternate, |
|
|
|
Easing = Easing.Parse("0.1123555056179775,0.657303370786517,0.8370786516853934,0.499999999999999999") |
|
|
|
}; |
|
|
|
|
|
|
|
var rotateTransform = new RotateTransform(-2.5); |
|
|
|
var rect = new Rectangle() |
|
|
|
{ |
|
|
|
RenderTransform = rotateTransform |
|
|
|
}; |
|
|
|
|
|
|
|
var clock = new TestClock(); |
|
|
|
var animationRun = animation.RunAsync(rect, clock); |
|
|
|
|
|
|
|
// position is what you'd expect at end and beginning
|
|
|
|
clock.Step(TimeSpan.Zero); |
|
|
|
Assert.Equal(rotateTransform.Angle, -2.5); |
|
|
|
clock.Step(TimeSpan.FromSeconds(5)); |
|
|
|
Assert.Equal(rotateTransform.Angle, 2.5); |
|
|
|
|
|
|
|
// test some points in between end and beginning
|
|
|
|
var tolerance = 0.01; |
|
|
|
clock.Step(TimeSpan.Parse("00:00:10.0153932")); |
|
|
|
var expected = -2.4122350198982545; |
|
|
|
Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance); |
|
|
|
|
|
|
|
clock.Step(TimeSpan.Parse("00:00:11.2655407")); |
|
|
|
expected = -0.37153223002125113; |
|
|
|
Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance); |
|
|
|
|
|
|
|
clock.Step(TimeSpan.Parse("00:00:12.6158773")); |
|
|
|
expected = 0.3967885416786294; |
|
|
|
Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance); |
|
|
|
|
|
|
|
clock.Step(TimeSpan.Parse("00:00:14.6495256")); |
|
|
|
expected = 1.8016358493761722; |
|
|
|
Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|