Replace Lerp functions.

This commit is contained in:
2024-10-15 23:26:28 +02:00
parent 446149c80d
commit 692fdf8ef0
2 changed files with 12 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ namespace Voile.Extensions
{ {
public static Vector2 Lerp(this Vector2 a, Vector2 b, double t) public static Vector2 Lerp(this Vector2 a, Vector2 b, double t)
{ {
return new Vector2(MathUtils.Lerp(a.X, b.X, t), MathUtils.Lerp(a.Y, b.Y, t)); return new Vector2((float)MathUtils.Lerp(a.X, b.X, t), (float)MathUtils.Lerp(a.Y, b.Y, t));
} }
} }
} }

View File

@@ -1,12 +1,21 @@
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices;
namespace Voile namespace Voile
{ {
public static class MathUtils public static class MathUtils
{ {
public static float Lerp(float a, float b, double t) => a + (b - a) * (float)t; [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static double LerpUnclamped(double a, double b, double t) => (a * (1d - t)) + (b * t);
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static float LerpUnclamped(float a, float b, float t) => (a * (1f - t)) + (b * t);
public static Color LerpColor(Color colorA, Color colorB, double t) [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static double Lerp(double a, double b, double t) => t <= 0d ? a : t >= 1d ? b : LerpUnclamped(a, b, t);
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static float Lerp(float a, float b, float t) => t <= 0f ? a : t >= 1f ? b : LerpUnclamped(a, b, t);
public static Color LerpColor(Color colorA, Color colorB, float t)
{ {
var r = Lerp(colorA.R, colorB.R, t); var r = Lerp(colorA.R, colorB.R, t);
var g = Lerp(colorA.G, colorB.G, t); var g = Lerp(colorA.G, colorB.G, t);