Ogeon / palette

A Rust library for linear color calculations and conversion
Apache License 2.0
748 stars 60 forks source link

Converting Okhsva color where the value is 0.0 to Srgba results in all components being NaN. #330

Closed akhudek closed 1 year ago

akhudek commented 1 year ago

When converting from Okhsva to Srgba using the clamped into_color with a color that has zero value, you get NaN for the Srgb components. I would expect this to return black. If the Okhsva value is even slightly non-zero it works as expected.

How To Reproduce

use palette::{IntoColor, Okhsva, Srgba};
let mut c: Okhsva = Srgba::new(255u8, 0, 0, 255).into_format().into_color();
c.value = 0.0;
let c2: Srgba<f32> = c.into_color();
println!("c2 {:?}", c3);

Expected Outcome

c2 should represent black.

Actual Outcome

All components of c2 are NaN.

Additional Details

Using palette 0.7.1;

Ogeon commented 1 year ago

Sounds like a divide by 0 somewhere. Thanks for reporting!

Ogeon commented 1 year ago

The fix has been released in 0.7.2.