Skip to content

Commit

Permalink
Sanitize NaN before scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareFlo committed Nov 16, 2024
1 parent c03a46e commit 0b90da4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ fn sanitize_nan(i: f32) -> f32 {

impl FromPrimitive<f32> for u8 {
fn from_primitive(float: f32) -> Self {
let inner = (float.clamp(0.0, 1.0) * u8::MAX as f32).round();
NumCast::from(sanitize_nan(inner)).unwrap()
let inner = (sanitize_nan(float).clamp(0.0, 1.0) * u8::MAX as f32).round();
NumCast::from(inner).unwrap()
}
}

impl FromPrimitive<f32> for u16 {
fn from_primitive(float: f32) -> Self {
let inner = (float.clamp(0.0, 1.0) * u16::MAX as f32).round();
NumCast::from(sanitize_nan(inner)).unwrap()
let inner = (sanitize_nan(float).clamp(0.0, 1.0) * u16::MAX as f32).round();
NumCast::from(inner).unwrap()
}
}

Expand Down

0 comments on commit 0b90da4

Please sign in to comment.