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
parent
commit
a521f7d860
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      samples/ControlCatalog/Pages/TabbedPage/FluidNavBar/FluidNavBar.cs
  2. 6
      samples/ControlCatalog/Pages/Transitions/CardStackPageTransition.cs
  3. 6
      src/Avalonia.Base/Animation/CrossFade.cs
  4. 6
      src/Avalonia.Base/Animation/Transitions/Rotate3DTransition.cs
  5. 2
      src/Avalonia.Base/Rendering/Composition/Animations/Interpolators.cs
  6. 4
      src/Avalonia.Base/Rendering/Composition/Expressions/BuiltInExpressionFfi.cs

2
samples/ControlCatalog/Pages/TabbedPage/FluidNavBar/FluidNavBar.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)
{

6
samples/ControlCatalog/Pages/Transitions/CardStackPageTransition.cs

@ -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)
{

6
src/Avalonia.Base/Animation/CrossFade.cs

@ -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));
}
}

6
src/Avalonia.Base/Animation/Transitions/Rotate3DTransition.cs

@ -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)

2
src/Avalonia.Base/Rendering/Composition/Animations/Interpolators.cs

@ -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) =>

4
src/Avalonia.Base/Rendering/Composition/Expressions/BuiltInExpressionFfi.cs

@ -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)
{

Loading…
Cancel
Save