Files
cpp-utils/Number.h
2026-01-24 16:10:02 -05:00

20 lines
469 B
C++

#ifndef NUMBER_UTILS_H
#define NUMBER_UTILS_H
#include <iostream>
#include <type_traits>
// Map a value with range, to another range.
template<typename T>
T mapRange(T value, T inMin, T inMax, T outMin, T outMax) {
static_assert(std::is_arithmetic<T>::value, "Template parameter must be a numeric type");
if (inMin == inMax) {
return value;
}
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
#endif //NUMBER_UTILS_H