mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 21:53:41 +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
6b0c81bf36
commit
078b1c8d86
2 changed files with 13 additions and 1 deletions
|
@ -363,4 +363,14 @@ float Bezier::angle(float t) const
|
||||||
return rad2deg(tvg::atan2(pt.y, pt.x));
|
return rad2deg(tvg::atan2(pt.y, pt.x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
return static_cast<uint8_t>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,8 @@ static inline T lerp(const T &start, const T &end, float t)
|
||||||
return static_cast<T>(start + (end - start) * t);
|
return static_cast<T>(start + (end - start) * t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t lerp(const uint8_t &start, const uint8_t &end, float t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //_TVG_MATH_H_
|
#endif //_TVG_MATH_H_
|
||||||
|
|
Loading…
Add table
Reference in a new issue