Skip to content

Commit

Permalink
Fix Color::as_rgba_linear for Color::Lcha (bevyengine#8040)
Browse files Browse the repository at this point in the history
Co-authored-by: James Liu <contact@jamessliu.com>
  • Loading branch information
2 people authored and Shfty committed Mar 19, 2023
1 parent 57594da commit 3bf3976
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/bevy_render/src/color/mod.rs
Expand Up @@ -525,7 +525,7 @@ impl Color {
let [red, green, blue] =
LchRepresentation::lch_to_nonlinear_srgb(*lightness, *chroma, *hue);

Color::Rgba {
Color::RgbaLinear {
red: red.nonlinear_to_linear_srgb(),
green: green.nonlinear_to_linear_srgb(),
blue: blue.nonlinear_to_linear_srgb(),
Expand Down Expand Up @@ -1858,4 +1858,22 @@ mod tests {

assert_eq!(starting_color * transformation, mutated_color,);
}

// regression test for https://github.com/bevyengine/bevy/pull/8040
#[test]
fn convert_to_rgba_linear() {
let rgba = Color::rgba(0., 0., 0., 0.);
let rgba_l = Color::rgba_linear(0., 0., 0., 0.);
let hsla = Color::hsla(0., 0., 0., 0.);
let lcha = Color::Lcha {
lightness: 0.0,
chroma: 0.0,
hue: 0.0,
alpha: 0.0,
};
assert_eq!(rgba_l, rgba_l.as_rgba_linear());
let Color::RgbaLinear { .. } = rgba.as_rgba_linear() else { panic!("from Rgba") };
let Color::RgbaLinear { .. } = hsla.as_rgba_linear() else { panic!("from Hsla") };
let Color::RgbaLinear { .. } = lcha.as_rgba_linear() else { panic!("from Lcha") };
}
}

0 comments on commit 3bf3976

Please sign in to comment.