Add math::clamp(x, low, high)
This commit is contained in:
parent
7f69077c0a
commit
2db6c32310
1 changed files with 8 additions and 0 deletions
|
|
@ -183,6 +183,14 @@ namespace psemek::math
|
||||||
return (x >= 0) ? std::fmod(x, m) : (m - std::fmod(-x, m));
|
return (x >= 0) ? std::fmod(x, m) : (m - std::fmod(-x, m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto clamp(T const & x, T const & low, T const & high)
|
||||||
|
{
|
||||||
|
using std::min;
|
||||||
|
using std::max;
|
||||||
|
return min(high, max(low, x));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool make_min(T & target, T const & source)
|
bool make_min(T & target, T const & source)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue