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

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

Static Public Member Functions

static constexpr Lerp mapRange (X iFromLow, X iFromHigh, Y iToLow, Y iToHigh) noexcept
 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 constexpr 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 )
inlineconstexprnoexcept

◆ Lerp() [2/2]

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

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
inlineconstexpr

◆ computeY()

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

◆ mapRange()

template<typename TFloat, typename X, typename Y>
constexpr Lerp mapRange ( X iFromLow,
X iFromHigh,
Y iToLow,
Y iToHigh )
inlinestaticconstexprnoexcept

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>
constexpr Y mapValue ( X iValue,
X iFromLow,
X iFromHigh,
Y iToLow,
Y iToHigh,
bool iClamp = true )
inlinestaticconstexpr

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 constexpr 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:89

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: