Browse Source
refactor(animation): use built-in float.Lerp/double.Lerp in transitions (#22043)
Replace hand-written linear interpolation formulas with the framework
Lerp helpers across animation code and the composition expression FFI.
pull/22069/head
IconHHw
1 month ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
10 additions and
16 deletions
-
samples/ControlCatalog/Pages/TabbedPage/FluidNavBar/FluidNavBar.cs
-
samples/ControlCatalog/Pages/Transitions/CardStackPageTransition.cs
-
src/Avalonia.Base/Animation/CrossFade.cs
-
src/Avalonia.Base/Animation/Transitions/Rotate3DTransition.cs
-
src/Avalonia.Base/Rendering/Composition/Animations/Interpolators.cs
-
src/Avalonia.Base/Rendering/Composition/Expressions/BuiltInExpressionFfi.cs
|
|
|
@ -604,7 +604,7 @@ namespace ControlCatalog.Pages |
|
|
|
while (measure.NextContour()); |
|
|
|
} |
|
|
|
|
|
|
|
private static float Lerp(float a, float b, float t) => a + (b - a) * t; |
|
|
|
private static float Lerp(float a, float b, float t) => float.Lerp(a, b, t); |
|
|
|
|
|
|
|
private static double LinearPoint(double x, double pIn, double pOut) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -424,10 +424,8 @@ public class CardStackPageTransition : PageSlide |
|
|
|
return sign * FarPeekAngle; |
|
|
|
} |
|
|
|
|
|
|
|
private static double Lerp(double from, double to, double t) |
|
|
|
{ |
|
|
|
return from + ((to - from) * Math.Clamp(t, 0.0, 1.0)); |
|
|
|
} |
|
|
|
private static double Lerp(double from, double to, double t) => |
|
|
|
double.Lerp(from, to, Math.Clamp(t, 0.0, 1.0)); |
|
|
|
|
|
|
|
private static int GetViewportZIndex(double offsetFromCenter, Visual visual, Visual? from, Visual? to) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -260,9 +260,7 @@ namespace Avalonia.Animation |
|
|
|
return FarPeekOpacity; |
|
|
|
} |
|
|
|
|
|
|
|
private static double Lerp(double from, double to, double t) |
|
|
|
{ |
|
|
|
return from + ((to - from) * Math.Clamp(t, 0.0, 1.0)); |
|
|
|
} |
|
|
|
private static double Lerp(double from, double to, double t) => |
|
|
|
double.Lerp(from, to, Math.Clamp(t, 0.0, 1.0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -244,10 +244,8 @@ public class Rotate3DTransition : PageSlide |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
private static double Lerp(double from, double to, double t) |
|
|
|
{ |
|
|
|
return from + ((to - from) * Math.Clamp(t, 0.0, 1.0)); |
|
|
|
} |
|
|
|
private static double Lerp(double from, double to, double t) => |
|
|
|
double.Lerp(from, to, Math.Clamp(t, 0.0, 1.0)); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public override void Reset(Visual visual) |
|
|
|
|
|
|
|
@ -77,7 +77,7 @@ namespace Avalonia.Rendering.Composition.Animations |
|
|
|
|
|
|
|
class ColorInterpolator : IInterpolator<Avalonia.Media.Color> |
|
|
|
{ |
|
|
|
static byte Lerp(float a, float b, float p) => (byte) Math.Max(0, Math.Min(255, (p * (b - a) + a))); |
|
|
|
static byte Lerp(float a, float b, float p) => (byte)Math.Clamp(float.Lerp(a, b, p), 0, 255); |
|
|
|
|
|
|
|
public static Avalonia.Media.Color |
|
|
|
LerpRGB(Avalonia.Media.Color to, Avalonia.Media.Color from, float progress) => |
|
|
|
|
|
|
|
@ -13,8 +13,8 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
private readonly DelegateExpressionFfi _registry; |
|
|
|
|
|
|
|
static float Lerp(float a, float b, float p) => p * (b - a) + a; |
|
|
|
static double Lerp(double a, double b, double p) => p * (b - a) + a; |
|
|
|
static float Lerp(float a, float b, float p) => float.Lerp(a, b, p); |
|
|
|
static double Lerp(double a, double b, double p) => double.Lerp(a, b, p); |
|
|
|
|
|
|
|
static Matrix3x2 Inverse(Matrix3x2 m) |
|
|
|
{ |
|
|
|
|