Clamp to prevent overflow when interpolating between two gradient stops.

Closes #397.
This commit is contained in:
Patrick Walton 2020-07-16 10:37:31 -07:00
parent 6a32f8c055
commit 1570c38217
1 changed files with 2 additions and 4 deletions

View File

@ -166,10 +166,8 @@ impl Gradient {
return lower_stop.color;
}
lower_stop.color
.to_f32()
.lerp(upper_stop.color.to_f32(), (t - lower_stop.offset) / denom)
.to_u8()
let ratio = ((t - lower_stop.offset) / denom).min(1.0);
lower_stop.color.to_f32().lerp(upper_stop.color.to_f32(), ratio).to_u8()
}
#[inline]