18 #ifndef __PONGASOFT_UTILS_MISC_H__ 19 #define __PONGASOFT_UTILS_MISC_H__ 21 #include <pongasoft/logging/logging.h> 32 template <
typename T,
typename U>
33 inline static T
clamp(
const U &iValue,
const T &iLower,
const T &iUpper)
35 auto v = static_cast<T>(iValue);
36 return v < iLower ? iLower : (v > iUpper ? iUpper : v);
43 template <
typename T,
typename U>
44 inline static T
clampRange(
const U &iValue,
const T &iFrom,
const T &iTo)
47 return clamp(iValue, iFrom, iTo);
49 return clamp(iValue, iTo, iFrom);
57 template <
typename T,
typename U>
58 inline static T
clampE(
const U &value,
const T &lower,
const T &upper)
60 auto v = static_cast<T>(value);
61 DCHECK_F(v >= lower && v <= upper);
62 return v < lower ? lower : (v > upper ? upper : value);
68 #endif // __PONGASOFT_UTILS_MISC_H__ static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Make sure that the value remains within its bounds.
Definition: Misc.h:33
static T clampE(const U &value, const T &lower, const T &upper)
Same as clamp except it will actually fail/assert in debug mode.
Definition: Misc.h:58
Definition: CircularBuffer.h:25
static T clampRange(const U &iValue, const T &iFrom, const T &iTo)
Make sure that the value remains within its bounds.
Definition: Misc.h:44