21template <
class T,
class U>
23 T
min = std::numeric_limits<T>::lowest();
24 T
max = std::numeric_limits<T>::max();
27 return (lhs >
max - rhs) ?
max : T(lhs + rhs);
30 return (lhs <
min - rhs) ?
min : T(lhs + rhs);
38template <
class T,
class U =
int>
39constexpr inline T&
Increase(T& obj, U diff = 1) {
47template <
class T,
class U =
int>
48constexpr inline T&
Decrease(T& obj, U diff = 1) {
60template <
class T,
class M,
class U =
int>
61constexpr inline decltype(
auto)
DecreaseMember(T& obj, M member, U diff = 1) {
62 obj.*member =
SafeAdd(obj.*member, -diff);
76template <
class T,
class S>
77auto mod(T v, S m) ->
decltype(v % m) {
88 if (
auto neg_v =
mod(-v, m)) {
100template <
class T,
class S>
102 return l < r ? l : r;
105template <
class T,
class S>
107 return l > r ? l : r;
116template <
class V,
class L,
class U>
117auto clamp(V value, L lower, U upper) {
118 return min(
max(value, lower), upper);
126template <
class T,
class S = T>
138 if ((diff < 0) ^
invert) {
Represents an interval by two unsigned integers [base, base + diff].
Definition: cs_Math.h:127
bool contains(T val)
Definition: cs_Math.h:151
bool invert
Definition: cs_Math.h:130
bool ClosureContains(T val)
Definition: cs_Math.h:159
bool InteriorContains(T val)
Definition: cs_Math.h:167
T lowerbound()
Definition: cs_Math.h:143
T low
Definition: cs_Math.h:129
Interval(T base, S diff, bool inv=false)
Definition: cs_Math.h:133
T high
Definition: cs_Math.h:129
T upperbound()
Definition: cs_Math.h:144
constexpr decltype(auto) DecreaseMember(T &obj, M member, U diff=1)
Identical to the other decrease function.
Definition: cs_Math.h:61
constexpr T & Increase(T &obj, U diff=1)
roll over safe variant of ++some_value;
Definition: cs_Math.h:39
constexpr T & Decrease(T &obj, U diff=1)
roll over safe variant of –some_value;
Definition: cs_Math.h:48
auto min(T l, S r)
Definition: cs_Math.h:101
constexpr T SafeAdd(T lhs, U rhs)
returns lhs+rhs, clamping return values that would roll over to the min/max values of lhs.
Definition: cs_Math.h:22
auto clamp(V value, L lower, U upper)
Returns:
Definition: cs_Math.h:117
auto max(T l, S r)
Definition: cs_Math.h:106
auto mod(T v, S m) -> decltype(v % m)
Returns the canonical representation of [v] considered as element of Z/mZ, regardless of any silly fe...
Definition: cs_Math.h:77
T round(float val)
Rounds a numeric value.
Definition: cs_Math.h:178