Jamba C++ API  4.4.0
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. More...
 

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]. More...
 
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]. More...
 

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]

Lerp ( iX1,
iY1,
iX2,
iY2 
)
inline

◆ Lerp() [2/2]

Lerp ( iY0,
iY1 
)
inline

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

Member Function Documentation

◆ computeX()

X computeX ( iY) const
inline

◆ computeY()

Y computeY ( iX) const
inline

◆ mapRange()

static Lerp mapRange ( iFromLow,
iFromHigh,
iToLow,
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()

static Y mapValue ( iValue,
iFromLow,
iFromHigh,
iToLow,
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

Member Data Documentation

◆ fA

const TFloat fA
private

◆ fB

const TFloat fB
private

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