Add celmath::clamp(val, low, high)

pull/324/head
Hleb Valoshka 2019-06-06 22:48:52 +03:00
parent 74144a85bc
commit 93c4a3b55c
2 changed files with 8 additions and 3 deletions

View File

@ -7877,10 +7877,9 @@ void Renderer::updateBodyVisibilityMask()
bodyVisibilityMask = flags;
}
void Renderer::setSolarSystemMaxDistance(float t)
void Renderer::setSolarSystemMaxDistance(float t)
{
if (t >= 1.0f && t <= 10.0f)
SolarSystemMaxDistance = t;
SolarSystemMaxDistance = clamp(t, 1.0f, 10.0f);
}
void Renderer::getScreenSize(int* x, int* y, int* w, int* h) const

View File

@ -47,6 +47,12 @@ template<typename T> constexpr T clamp(T t)
return (t < 0) ? 0 : ((t > 1) ? 1 : t);
}
// return t clamped to [low, high]
template<typename T> constexpr T clamp(T t, T low, T high)
{
return (t < low) ? low : ((t > high) ? high : t);
}
template<typename T> inline constexpr T degToRad(T d)
{
return d / 180 * static_cast<T>(PI);