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 : iValue);
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);
69 #endif // __PONGASOFT_UTILS_MISC_H__ static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Definition: Misc.h:33
static T clampE(const U &value, const T &lower, const T &upper)
Definition: Misc.h:58
static T clampRange(const U &iValue, const T &iFrom, const T &iTo)
Definition: Misc.h:44