Skip to content
Snippets Groups Projects
Commit d60290ae authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add rescale

parent 230de565
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,7 @@ SET(INCLUDES
math/normal/normal_to_mat4.h
math/SoftMinMax.h
math/rescale.h
meta/eigen/enable_if_compile_time_size.h
meta/eigen/is_eigen_matrix.h
......
......@@ -9,3 +9,4 @@
#include "math/periodic.h"
#include "math/periodic_clamp.h"
#include "math/pose.h"
#include "math/rescale.h"
#pragma once
#include <type_traits>
namespace simox::math
{
template <class Float,
std::enable_if_t<std::is_floating_point_v<Float>, int> = 0>
inline
/// Rescale a scalar `value` from interval `[from_lo, from_hi]` to `[to_lo, to_hi]`.
Float rescale(Float value, Float from_lo, Float from_hi, Float to_lo, Float to_hi)
{
// value: [from_lo, from_hi]
Float norm = (value - from_lo) / (from_hi - from_lo); // [0, 1]
return norm * (to_hi - to_lo) + to_lo; // [to_lo, to_hi]
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment