diff --git a/Voile/Source/Extensions/Vector2Extensions.cs b/Voile/Source/Extensions/Vector2Extensions.cs index 7727f52..6c72e68 100644 --- a/Voile/Source/Extensions/Vector2Extensions.cs +++ b/Voile/Source/Extensions/Vector2Extensions.cs @@ -6,7 +6,7 @@ namespace Voile.Extensions { 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)); } } } \ No newline at end of file diff --git a/Voile/Source/Utils/MathUtils.cs b/Voile/Source/Utils/MathUtils.cs index 043e87a..7f98031 100644 --- a/Voile/Source/Utils/MathUtils.cs +++ b/Voile/Source/Utils/MathUtils.cs @@ -1,12 +1,21 @@ using System.Numerics; +using System.Runtime.CompilerServices; namespace Voile { 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 g = Lerp(colorA.G, colorB.G, t);