Class MathExtensions
- Namespace
- BSGameLib.Core
- Assembly
- BSGameLib.Core.dll
Extensions for limiting and range-checking numbers.
public static class MathExtensions
- Inheritance
-
MathExtensions
- Inherited Members
Methods
Clamp<T>(T, T, T)
Generic method to limit the value of 'val' to be a minimum of 'min' and a maximum of 'max'.
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
Parameters
valTThe value to be limited
minTThe minimum value of val.
maxTThe maximum value of val.
Returns
- T
Returns min if val < min, max if val > max, otherwise val.
Type Parameters
TImplements IComparable, so any that it is compatible with.
OutOfRangeDefault<T>(T, T, T, T)
Returns defaultValue when val is below
min or above max; otherwise returns
val. Both bounds are inclusive.
public static T OutOfRangeDefault<T>(this T val, T min, T max, T defaultValue) where T : IComparable<T>
Parameters
valTminTmaxTdefaultValueT
Returns
- T
Type Parameters
T