mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-19 18:18:09 +08:00
Fix linear_gradient float precision bug.
This was reported by: https://github.com/ArthurSonzogni/FTXUI/issues/998 Indeed, the `t` interpolation factor, which is itself interpolated might become slightly larger than 1.0. This is due to the float precision. This was supposedly handled, but there was an off-by-one error in the check. Along the way, fix a bug found by a fuzzer. Bug: https://github.com/ArthurSonzogni/FTXUI/issues/998 Fixed: https://github.com/ArthurSonzogni/FTXUI/issues/998
This commit is contained in:

committed by
ArthurSonzogni

parent
15587dad01
commit
d75108e960
@@ -97,7 +97,11 @@ Color Interpolate(const LinearGradientNormalized& gradient, float t) {
|
||||
// Find the right color in the gradient's stops.
|
||||
size_t i = 1;
|
||||
while (true) {
|
||||
if (i > gradient.positions.size()) {
|
||||
// Note that `t` might be slightly greater than 1.0 due to floating point
|
||||
// precision. This is why we need to handle the case where `t` is greater
|
||||
// than the last stop's position.
|
||||
// See https://github.com/ArthurSonzogni/FTXUI/issues/998
|
||||
if (i >= gradient.positions.size()) {
|
||||
const float half = 0.5F;
|
||||
return Color::Interpolate(half, gradient.colors.back(),
|
||||
gradient.colors.back());
|
||||
|
Reference in New Issue
Block a user