mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
common: introduce tvg::clamp
This commit is contained in:
parent
b71b329a01
commit
59f950e71b
2 changed files with 8 additions and 2 deletions
|
@ -367,8 +367,7 @@ float Bezier::angle(float t) const
|
|||
uint8_t lerp(const uint8_t &start, const uint8_t &end, float t)
|
||||
{
|
||||
auto result = static_cast<int>(start + (end - start) * t);
|
||||
if (result > 255) result = 255;
|
||||
else if (result < 0) result = 0;
|
||||
tvg::clamp(result, 0, 255);
|
||||
return static_cast<uint8_t>(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,13 @@ static inline bool equal(float a, float b)
|
|||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static inline void clamp(T& v, const T& min, const T& max)
|
||||
{
|
||||
if (v < min) v = min;
|
||||
else if (v > max) v = max;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* Matrix functions */
|
||||
/************************************************************************/
|
||||
|
|
Loading…
Add table
Reference in a new issue