1
0
Fork 0
mirror of https://codeberg.org/kbruen/y3s2-gui-project.git synced 2025-04-20 23:03:56 +03:00
y3s2-gui-project/src/utils.hpp

30 lines
568 B
C++
Raw Normal View History

2022-03-21 01:39:06 +02:00
#pragma once
namespace Utils {
const double PI = 3.14159265358979323846;
template <typename T>
T nummap(T input, T inMin, T inMax, T outMin, T outMax) {
// From: https://www.arduino.cc/reference/en/language/functions/math/map/
return (input - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
2022-06-05 02:17:49 +03:00
template <typename T>
T clamp(T input, T min, T max) {
if (input < min) {
return min;
}
else if (input > max) {
return max;
}
else {
return input;
}
}
2022-03-21 01:39:06 +02:00
template <typename T>
constexpr T toRad(T deg) {
return deg * PI / 180;
}
2022-03-21 09:10:18 +02:00
}