19#ifndef __PONGASOFT_UTILS_MISC_H__
20#define __PONGASOFT_UTILS_MISC_H__
22#include <pongasoft/logging/logging.h>
33template <
typename T,
typename U>
34inline static T
clamp(
const U &iValue,
const T &iLower,
const T &iUpper)
36 auto v =
static_cast<T
>(iValue);
37 return v < iLower ? iLower : (v > iUpper ? iUpper : v);
44template <
typename T,
typename U>
45inline static T
clampRange(
const U &iValue,
const T &iFrom,
const T &iTo)
48 return clamp(iValue, iFrom, iTo);
50 return clamp(iValue, iTo, iFrom);
58template <
typename T,
typename U>
59inline static T
clampE(
const U &value,
const T &lower,
const T &upper)
61 auto v =
static_cast<T
>(value);
62 DCHECK_F(v >= lower && v <= upper);
63 return v < lower ? lower : (v > upper ? upper : value);
Definition CircularBuffer.h:26
static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Make sure that the value remains within its bounds.
Definition Misc.h:34
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:59
static T clampRange(const U &iValue, const T &iFrom, const T &iTo)
Make sure that the value remains within its bounds.
Definition Misc.h:45