Compare commits
3 commits
7ed67fcd41
...
880bbba491
| Author | SHA1 | Date | |
|---|---|---|---|
| 880bbba491 | |||
| 2db6c32310 | |||
| 7f69077c0a |
2 changed files with 23 additions and 1 deletions
|
|
@ -287,7 +287,9 @@ namespace psemek::math
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T clamp(T x, interval<T> const & i)
|
T clamp(T x, interval<T> const & i)
|
||||||
{
|
{
|
||||||
return std::max(i.min, std::min(i.max, x));
|
using std::min;
|
||||||
|
using std::max;
|
||||||
|
return max(i.min, min(i.max, x));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
@ -222,6 +230,12 @@ namespace psemek::math
|
||||||
return x * x * (T{3} - T{2} * x);
|
return x * x * (T{3} - T{2} * x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T smoothstep(T edge0, T edge1, T x)
|
||||||
|
{
|
||||||
|
return smoothstep(clamp((x - edge0) / (edge1 - edge0), T{0}, T{1}));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T smootherstep(T x)
|
T smootherstep(T x)
|
||||||
{
|
{
|
||||||
|
|
@ -229,6 +243,12 @@ namespace psemek::math
|
||||||
return x * x2 * (T{10} - x * T{15} + x2 * T{6});
|
return x * x2 * (T{10} - x * T{15} + x2 * T{6});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T smootherstep(T edge0, T edge1, T x)
|
||||||
|
{
|
||||||
|
return smootherstep(clamp((x - edge0) / (edge1 - edge0), T{0}, T{1}));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T inverse_smoothstep(T x)
|
T inverse_smoothstep(T x)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue