mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
common: uint8_t version of the lerp
An uint8_t version of the lerp function is introduced to handle cases where the interpolation factor t exceeds 1, which previously caused overflow issues due to casting.
This commit is contained in:
parent
c30447be98
commit
94047ffd36
2 changed files with 10 additions and 1 deletions
|
@ -132,4 +132,12 @@ Point operator*(const Point& pt, const Matrix& m)
|
|||
auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13;
|
||||
auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23;
|
||||
return {tx, ty};
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t mathLerp(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;
|
||||
return static_cast<uint8_t>(result);
|
||||
}
|
||||
|
|
|
@ -259,5 +259,6 @@ static inline T mathLerp(const T &start, const T &end, float t)
|
|||
return static_cast<T>(start + (end - start) * t);
|
||||
}
|
||||
|
||||
uint8_t mathLerp(const uint8_t &start, const uint8_t &end, float t);
|
||||
|
||||
#endif //_TVG_MATH_H_
|
||||
|
|
Loading…
Add table
Reference in a new issue