Skip to content

Commit

Permalink
Color::Lcha constructors (bevyengine#8041)
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 3bf3976 commit 57a4d7a
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions crates/bevy_render/src/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,43 @@ 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
Expand Down Expand Up @@ -1865,12 +1902,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") };
Expand Down

0 comments on commit 57a4d7a

Please sign in to comment.