Skip to content

Commit 7d5f89c

Browse files
payloadjames7132
andauthored
Color::Lcha constructors (#8041)
Co-authored-by: James Liu <[email protected]>
1 parent 9e9ae5b commit 7d5f89c

File tree

1 file changed

+38
-6
lines changed
  • crates/bevy_render/src/color

1 file changed

+38
-6
lines changed

crates/bevy_render/src/color/mod.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,43 @@ impl Color {
253253
}
254254
}
255255

256+
/// New `Color` with LCH representation in sRGB colorspace.
257+
///
258+
/// # Arguments
259+
///
260+
/// * `lightness` - Lightness channel. [0.0, 1.5]
261+
/// * `chroma` - Chroma channel. [0.0, 1.5]
262+
/// * `hue` - Hue channel. [0.0, 360.0]
263+
///
264+
/// See also [`Color::lcha`].
265+
pub const fn lch(lightness: f32, chroma: f32, hue: f32) -> Color {
266+
Color::Lcha {
267+
lightness,
268+
chroma,
269+
hue,
270+
alpha: 1.0,
271+
}
272+
}
273+
274+
/// New `Color` with LCH representation in sRGB colorspace.
275+
///
276+
/// # Arguments
277+
///
278+
/// * `lightness` - Lightness channel. [0.0, 1.5]
279+
/// * `chroma` - Chroma channel. [0.0, 1.5]
280+
/// * `hue` - Hue channel. [0.0, 360.0]
281+
/// * `alpha` - Alpha channel. [0.0, 1.0]
282+
///
283+
/// See also [`Color::lch`].
284+
pub const fn lcha(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Color {
285+
Color::Lcha {
286+
lightness,
287+
chroma,
288+
hue,
289+
alpha,
290+
}
291+
}
292+
256293
/// New `Color` from sRGB colorspace.
257294
///
258295
/// # Examples
@@ -1865,12 +1902,7 @@ mod tests {
18651902
let rgba = Color::rgba(0., 0., 0., 0.);
18661903
let rgba_l = Color::rgba_linear(0., 0., 0., 0.);
18671904
let hsla = Color::hsla(0., 0., 0., 0.);
1868-
let lcha = Color::Lcha {
1869-
lightness: 0.0,
1870-
chroma: 0.0,
1871-
hue: 0.0,
1872-
alpha: 0.0,
1873-
};
1905+
let lcha = Color::lcha(0., 0., 0., 0.);
18741906
assert_eq!(rgba_l, rgba_l.as_rgba_linear());
18751907
let Color::RgbaLinear { .. } = rgba.as_rgba_linear() else { panic!("from Rgba") };
18761908
let Color::RgbaLinear { .. } = hsla.as_rgba_linear() else { panic!("from Hsla") };

0 commit comments

Comments
 (0)