Skip to content

Commit

Permalink
Fix Color::as_rgba_linear for Color::Lcha
Browse files Browse the repository at this point in the history
  • Loading branch information
payload committed Mar 11, 2023
1 parent ee0e6f4 commit 2b229d6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/bevy_render/src/color/mod.rs
Original file line number Diff line number Diff line change
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,21 @@ mod tests {

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

#[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 2b229d6

Please sign in to comment.