Skip to content

Commit 1570c38

Browse files
committed
Clamp to prevent overflow when interpolating between two gradient stops.
Closes #397.
1 parent 6a32f8c commit 1570c38

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

content/src/gradient.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,8 @@ impl Gradient {
166166
return lower_stop.color;
167167
}
168168

169-
lower_stop.color
170-
.to_f32()
171-
.lerp(upper_stop.color.to_f32(), (t - lower_stop.offset) / denom)
172-
.to_u8()
169+
let ratio = ((t - lower_stop.offset) / denom).min(1.0);
170+
lower_stop.color.to_f32().lerp(upper_stop.color.to_f32(), ratio).to_u8()
173171
}
174172

175173
#[inline]

0 commit comments

Comments
 (0)