Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Color::as_rgba_linear for Color::Lcha #8040

Merged
merged 2 commits into from Mar 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]
payload marked this conversation as resolved.
Show resolved Hide resolved
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") };
}
}