From ec5160c060b285ee82d0404f9d740a31f1a8b6d7 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 31 Mar 2022 14:51:18 -0700 Subject: [PATCH] add int variant to MathHelper.Approach --- src/Math/MathHelper.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Math/MathHelper.cs b/src/Math/MathHelper.cs index f53876c..d3ffb5a 100644 --- a/src/Math/MathHelper.cs +++ b/src/Math/MathHelper.cs @@ -360,6 +360,19 @@ namespace MoonWorks.Math System.Math.Max(start - change, end); } + /// + /// Step from start towards end by change. + /// + /// Start value. + /// End value. + /// Change value. + public static int Approach(int start, int end, int change) + { + return start < end ? + System.Math.Min(start + change, end) : + System.Math.Max(start - change, end); + } + #endregion #region Internal Static Methods