add int variant to MathHelper.Approach

pull/18/head
cosmonaut 2022-03-31 14:51:18 -07:00
parent c96c7a0d90
commit ec5160c060
1 changed files with 13 additions and 0 deletions

View File

@ -354,6 +354,19 @@ namespace MoonWorks.Math
/// <param name="end">End value.</param> /// <param name="end">End value.</param>
/// <param name="change">Change value.</param> /// <param name="change">Change value.</param>
public static float Approach(float start, float end, float change) public static float Approach(float start, float end, float change)
{
return start < end ?
System.Math.Min(start + change, end) :
System.Math.Max(start - change, end);
}
/// <summary>
/// Step from start towards end by change.
/// </summary>
/// <param name="start">Start value.</param>
/// <param name="end">End value.</param>
/// <param name="change">Change value.</param>
public static int Approach(int start, int end, int change)
{ {
return start < end ? return start < end ?
System.Math.Min(start + change, end) : System.Math.Min(start + change, end) :