16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

Refactor clamp_circular

This commit is contained in:
docentYT
2026-05-02 00:07:06 +02:00
parent d1f16411a1
commit 76844e33e7

View File

@@ -252,13 +252,19 @@ template <typename T> bool is_equal(T const &Left, T const &Right, T const Epsil
}
// keeps the provided value in specified range 0-Range, as if the range was circular buffer
template <typename Type_> Type_ clamp_circular(Type_ Value, Type_ const Range = static_cast<Type_>(360))
template <typename T> T clamp_circular(T Value, T const Range = T(360))
{
if constexpr (std::is_floating_point_v<T>)
{
Value = std::fmod(Value, Range);
}
else
{
Value %= Range;
}
Value -= Range * (int)(Value / Range); // clamp the range to 0-360
if (Value < Type_(0))
if (Value < T(0))
Value += Range;
return Value;
}