template<typename TFloat, typename X, typename Y>
class pongasoft::Utils::Lerp< TFloat, X, Y >
Util class to compute linear interpolation. Use SPLerp/DPLerp and mapValueSP/mapRangeSP (resp mapValueDP/mapRangeDP) for convenience.
Providing iX1 == iX2 will result in undefined behavior
template<typename TFloat , typename X , typename Y >
Inspired by the map function in Processing language, another way to look at Lerp is to map a range of values into another range: [iFromLow, iFromHigh] -> [iToLow, iToHigh]. Note that low can be greater than high: for example you can map [1, -1] to the range [0, height] (display where 0 is at the top and height is the bottom)
template<typename TFloat , typename X , typename Y >
static Y pongasoft::Utils::Lerp< TFloat, X, Y >::mapValue |
( |
X |
iValue, |
|
|
X |
iFromLow, |
|
|
X |
iFromHigh, |
|
|
Y |
iToLow, |
|
|
Y |
iToHigh, |
|
|
bool |
iClamp = true |
|
) |
| |
|
inlinestatic |
Inspired by the map function in Processing language, another way to look at Lerp is to map a range of values into another range: [iFromLow, iFromHigh] -> [iToLow, iToHigh]. This function then return the iValue mapped from the first range into the second range. When iClamp is set to true, the incoming value will first be clamped to the from range. ex:
mapValue(5, 10, 20, 100, 200, true) returns 100 mapValue(5, 10, 20, 100, 200, false) returns 50
- Parameters
-
iValue | will be constrained to the range [min(iFromLow, iFromHigh), max(iFromLow, iFromHigh)] |