1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:45:41 +00:00

Inline float arithmetic, don't cast

This commit is contained in:
Oliver Booth 2022-04-20 18:50:06 +01:00
parent 778d8c6cf1
commit 37c7b74379
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 4 additions and 2 deletions

View File

@ -16,7 +16,9 @@
/// </returns>
public static float Lerp(float value, float target, float alpha)
{
return (float)Lerp(value * 1.0, target, alpha);
// rookie mistake: a + t * (b - a)
// "precise" method: (1 - t) * a + t * b
return ((1.0f - alpha) * value) + (alpha * target);
}
/// <summary>

View File

@ -121,6 +121,6 @@ public static class SingleExtensions
/// <returns><paramref name="value" /> rounded to the nearest multiple of <paramref name="nearest" />.</returns>
public static float Round(this float value, float nearest)
{
return (float)((double)value).Round(nearest);
return MathF.Round(value / nearest) * nearest;
}
}