31 template <
typename TFloat,
typename X,
typename Y>
35 Lerp(X iX1, Y iY1, X iX2, Y iY2) :
36 fA((static_cast<TFloat>(iY1 - iY2)) / (static_cast<TFloat>(iX1 - iX2))),
37 fB(static_cast<TFloat>(iY1) -
fA * static_cast<TFloat>(iX1)) {}
42 Lerp(Y iY0, Y iY1) :
fA(static_cast<TFloat>(iY1 - iY0)),
fB(static_cast<TFloat>(iY0)) {};
46 return static_cast<Y>((static_cast<TFloat>(iX) *
fA) +
fB);
52 return static_cast<X>((static_cast<TFloat>(iY) -
fB) /
fA);
60 static inline Lerp mapRange(X iFromLow, X iFromHigh, Y iToLow, Y iToHigh)
62 return Lerp(iFromLow, iToLow, iFromHigh, iToHigh);
76 static Y
mapValue(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh,
bool iClamp =
true)
79 if(iFromLow == iFromHigh)
80 return iValue <= iFromLow ? iToLow : iToHigh;
88 iValue =
clampRange(iValue, iFromLow, iFromHigh);
91 return Lerp(iFromLow, iToLow, iFromHigh, iToHigh).computeY(iValue);
102 template<
typename X,
typename Y>
115 template<
typename X,
typename Y>
131 template<
typename X,
typename Y>
132 inline static Y
mapValueSPXY(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh,
bool iClamp =
true)
140 inline static Y
mapValueSPY(
float iValue,
float iFromLow,
float iFromHigh, Y iToLow, Y iToHigh,
bool iClamp =
true)
148 inline static float mapValueSPX(X iValue, X iFromLow, X iFromHigh,
float iToLow,
float iToHigh,
bool iClamp =
true)
155 inline static float mapValueSP(
float iValue,
float iFromLow,
float iFromHigh,
float iToLow,
float iToHigh,
bool iClamp =
true)
157 return SPLerp::mapValue(iValue, iFromLow, iFromHigh, iToLow, iToHigh, iClamp);
164 template<
typename X,
typename Y>
177 template<
typename X,
typename Y>
193 template<
typename X,
typename Y>
194 inline static Y
mapValueDPXY(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh,
bool iClamp =
true)
202 inline static Y
mapValueDPY(
double iValue,
double iFromLow,
double iFromHigh, Y iToLow, Y iToHigh,
bool iClamp =
true)
210 inline static double mapValueDPX(X iValue, X iFromLow, X iFromHigh,
double iToLow,
double iToHigh,
bool iClamp =
true)
217 inline static double mapValueDP(
double iValue,
double iFromLow,
double iFromHigh,
double iToLow,
double iToHigh,
bool iClamp =
true)
219 return DPLerp::mapValue(iValue, iFromLow, iFromHigh, iToLow, iToHigh, iClamp);
257 template<
typename U,
typename TLerp = DPLerpXY<T, U>>
260 return TLerp::mapValue(iValue,
fFrom,
fTo, iRange.
fFrom, iRange.
fTo, iClampToRange);
269 template<
typename U,
typename TLerp = DPLerpXY<T, U>>
272 return mapSubRange<U,TLerp>(*
this, iRange, iClampToRange);
281 template<
typename U,
typename TLerp = DPLerpXY<T, U>>
285 return Range<U>{mapValue<U,TLerp>(iSubRange.
fFrom, iRange, iClampToRange),
286 mapValue<U,TLerp>(iSubRange.
fTo, iRange, iClampToRange)};
307 return !(rhs == *
this);
static SPLerpXY< X, Y > mapRangeSPXY(X iFromLow, X iFromHigh, Y iToLow, Y iToHigh)
Definition: Lerp.h:116
bool isSingleValue() const
Definition: Lerp.h:238
Y computeY(X iX) const
Definition: Lerp.h:44
T clamp(T iValue) const
Definition: Lerp.h:245
T fTo
Definition: Lerp.h:312
Range(T iValue) noexcept
Definition: Lerp.h:232
Range< U > cast() const
Definition: Lerp.h:293
constexpr auto mapRangeSPY
Definition: Lerp.h:122
constexpr auto mapRangeSPX
Definition: Lerp.h:125
static double mapValueDP(double iValue, double iFromLow, double iFromHigh, double iToLow, double iToHigh, bool iClamp=true)
Definition: Lerp.h:217
const TFloat fA
Definition: Lerp.h:95
U mapValue(T iValue, Range< U > const &iRange, bool iClampToRange=true) const
Definition: Lerp.h:258
static DPLerpXY< X, Y > mapRangeDPXY(X iFromLow, X iFromHigh, Y iToLow, Y iToHigh)
Definition: Lerp.h:178
static Y mapValue(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
Definition: Lerp.h:76
Range(T iFrom, T iTo)
Definition: Lerp.h:235
static Lerp mapRange(X iFromLow, X iFromHigh, Y iToLow, Y iToHigh)
Definition: Lerp.h:60
static T clampRange(const U &iValue, const T &iFrom, const T &iTo)
Definition: Misc.h:44
static float mapValueSP(float iValue, float iFromLow, float iFromHigh, float iToLow, float iToHigh, bool iClamp=true)
Definition: Lerp.h:155
Range< U > mapRange(Range< U > const &iRange, bool iClampToRange=true) const
Definition: Lerp.h:270
bool operator==(const Range &rhs) const
Definition: Lerp.h:299
static double mapValueDPX(X iValue, X iFromLow, X iFromHigh, double iToLow, double iToHigh, bool iClamp=true)
Definition: Lerp.h:210
Lerp(Y iY0, Y iY1)
Definition: Lerp.h:42
Lerp(X iX1, Y iY1, X iX2, Y iY2)
Definition: Lerp.h:35
constexpr auto mapRangeDPY
Definition: Lerp.h:184
static Y mapValueDPXY(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
Definition: Lerp.h:194
Range< U > mapSubRange(Range< T > const &iSubRange, Range< U > const &iRange, bool iClampToRange=true) const
Definition: Lerp.h:282
constexpr auto mapRangeDPX
Definition: Lerp.h:187
static Y mapValueDPY(double iValue, double iFromLow, double iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
Definition: Lerp.h:202
constexpr auto mapRangeDP
Definition: Lerp.h:189
static Y mapValueSPXY(X iValue, X iFromLow, X iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
Definition: Lerp.h:132
constexpr auto mapRangeSP
Definition: Lerp.h:127
static float mapValueSPX(X iValue, X iFromLow, X iFromHigh, float iToLow, float iToHigh, bool iClamp=true)
Definition: Lerp.h:148
T fFrom
Definition: Lerp.h:311
bool operator!=(const Range &rhs) const
Definition: Lerp.h:305
const TFloat fB
Definition: Lerp.h:96
X computeX(Y iY) const
Definition: Lerp.h:49
static Y mapValueSPY(float iValue, float iFromLow, float iFromHigh, Y iToLow, Y iToHigh, bool iClamp=true)
Definition: Lerp.h:140