From ffa6c5f1f147399b11a5a3391bc94a89cad960af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilbert=20R=C3=B6hrbein?= Date: Sat, 11 Mar 2023 12:09:47 +0100 Subject: [PATCH 1/2] Add Color::lch and Color::lcha constructors --- crates/bevy_render/src/color/mod.rs | 46 +++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/crates/bevy_render/src/color/mod.rs b/crates/bevy_render/src/color/mod.rs index a5fa2c2b0889c..84f1e7ecfbb12 100644 --- a/crates/bevy_render/src/color/mod.rs +++ b/crates/bevy_render/src/color/mod.rs @@ -253,6 +253,45 @@ impl Color { } } + /// New `Color` with LCH representation in sRGB colorspace. + /// + /// # Arguments + /// + /// * `lightness` - Lightness channel. [0.0, 1.5] + /// * `chroma` - Chroma channel. [0.0, 1.5] + /// * `hue` - Hue channel. [0.0, 360.0] + /// + /// See also [`Color::lcha`]. + /// + pub const fn lch(lightness: f32, chroma: f32, hue: f32) -> Color { + Color::Lcha { + lightness, + chroma, + hue, + alpha: 1.0, + } + } + + /// New `Color` with LCH representation in sRGB colorspace. + /// + /// # Arguments + /// + /// * `lightness` - Lightness channel. [0.0, 1.5] + /// * `chroma` - Chroma channel. [0.0, 1.5] + /// * `hue` - Hue channel. [0.0, 360.0] + /// * `alpha` - Alpha channel. [0.0, 1.0] + /// + /// See also [`Color::lch`]. + /// + pub const fn lcha(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Color { + Color::Lcha { + lightness, + chroma, + hue, + alpha, + } + } + /// New `Color` from sRGB colorspace. /// /// # Examples @@ -1865,12 +1904,7 @@ mod tests { 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, - }; + let lcha = Color::lcha(0., 0., 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") }; From ef2ec7dcb92c69e1c96364c8e05c6c6ab57903a6 Mon Sep 17 00:00:00 2001 From: James Liu Date: Sat, 11 Mar 2023 10:36:04 -0800 Subject: [PATCH 2/2] Apply suggestions from code review --- crates/bevy_render/src/color/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/bevy_render/src/color/mod.rs b/crates/bevy_render/src/color/mod.rs index 84f1e7ecfbb12..d66a455cba297 100644 --- a/crates/bevy_render/src/color/mod.rs +++ b/crates/bevy_render/src/color/mod.rs @@ -262,7 +262,6 @@ impl Color { /// * `hue` - Hue channel. [0.0, 360.0] /// /// See also [`Color::lcha`]. - /// pub const fn lch(lightness: f32, chroma: f32, hue: f32) -> Color { Color::Lcha { lightness, @@ -282,7 +281,6 @@ impl Color { /// * `alpha` - Alpha channel. [0.0, 1.0] /// /// See also [`Color::lch`]. - /// pub const fn lcha(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Color { Color::Lcha { lightness,