Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
Lerp< TFloat, X, Y > Class Template Reference

Util class to compute linear interpolation. More...

#include <Lerp.h>

Public Member Functions

computeX (Y iY) const
computeY (X iX) const
 Lerp (X iX1, Y iY1, X iX2, Y iY2)
 Lerp (Y iY0, Y iY1)
 Shortcut for when x=0 => iY0 and x=1.0 => iY1.

Static Public Member Functions

static Lerp mapRange (X iFromLow, X iFromHigh, Y iToLow, Y iToHigh)
 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].
static Y mapValue (X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
 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].

Private Attributes

const TFloat fA
const TFloat fB

Detailed Description

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

Constructor & Destructor Documentation

◆ Lerp() [1/2]

template<typename TFloat, typename X, typename Y>
Lerp ( X iX1,
Y iY1,
X iX2,
Y iY2 )
inline

◆ Lerp() [2/2]

template<typename TFloat, typename X, typename Y>
Lerp ( Y iY0,
Y iY1 )
inline

Shortcut for when x=0 => iY0 and x=1.0 => iY1.

Member Function Documentation

◆ computeX()

template<typename TFloat, typename X, typename Y>
X computeX ( Y iY) const
inline

◆ computeY()

template<typename TFloat, typename X, typename Y>
Y computeY ( X iX) const
inline

◆ mapRange()

template<typename TFloat, typename X, typename Y>
Lerp mapRange ( X iFromLow,
X iFromHigh,
Y iToLow,
Y iToHigh )
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].

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)

◆ mapValue()

template<typename TFloat, typename X, typename Y>
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 returns 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:

// 15 is inside "from" range
mapValue(15, 10, 20, 100, 200); // returns 150
// 5 is outside "from" range
mapValue(5, 10, 20, 100, 200, true); // returns 100
mapValue(5, 10, 20, 100, 200, false); // returns 50
static Y mapValue(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
Inspired by the map function in Processing language, another way to look at Lerp is to map a range of...
Definition Lerp.h:80

Member Data Documentation

◆ fA

template<typename TFloat, typename X, typename Y>
const TFloat fA
private

◆ fB

template<typename TFloat, typename X, typename Y>
const TFloat fB
private

The documentation for this class was generated from the following file: