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

Color::Lcha constructors #8041

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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