diff options
Diffstat (limited to 'Impostor-dev/src/Impostor.Api/Unity/Mathf.cs')
-rw-r--r-- | Impostor-dev/src/Impostor.Api/Unity/Mathf.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Impostor-dev/src/Impostor.Api/Unity/Mathf.cs b/Impostor-dev/src/Impostor.Api/Unity/Mathf.cs new file mode 100644 index 0000000..4b03417 --- /dev/null +++ b/Impostor-dev/src/Impostor.Api/Unity/Mathf.cs @@ -0,0 +1,54 @@ +namespace Impostor.Api.Unity +{ + public static class Mathf + { + /// <summary> + /// <para>Clamps the given value between the given minimum float and maximum float values. Returns the given value if it is within the min and max range.</para> + /// </summary> + /// <param name="value">The floating point value to restrict inside the range defined by the min and max values.</param> + /// <param name="min">The minimum floating point value to compare against.</param> + /// <param name="max">The maximum floating point value to compare against.</param> + /// <returns> + /// <para>The float result between the min and max values.</para> + /// </returns> + public static float Clamp(float value, float min, float max) + { + if (value < (double)min) + { + value = min; + } + else if (value > (double)max) + { + value = max; + } + + return value; + } + + /// <summary> + /// <para>Clamps value between 0 and 1 and returns value.</para> + /// </summary> + /// <param name="value">Value.</param> + /// <returns>Clamped value.</returns> + public static float Clamp01(float value) + { + if (value < 0.0) + { + return 0.0f; + } + + return (double)value > 1.0 ? 1f : value; + } + + /// <summary> + /// <para>Linearly interpolates between a and b by t.</para> + /// </summary> + /// <param name="a">The start value.</param> + /// <param name="b">The end value.</param> + /// <param name="t">The interpolation value between the two floats.</param> + /// <returns> + /// <para>The interpolated float result between the two float values.</para> + /// </returns> + public static float Lerp(float a, float b, float t) => a + ((b - a) * Clamp01(t)); + } +}
\ No newline at end of file |