chromatic/spaces/grey/
mod.rs

1//! Monochrome colour representation.
2
3use num_traits::Float;
4
5mod colour;
6mod convert;
7mod fmt;
8
9/// Monochrome colour.
10#[derive(Debug, Clone, Copy)]
11pub struct Grey<T: Float + Send + Sync> {
12    /// Grey component.
13    grey: T,
14}
15
16impl<T: Float + Send + Sync> Grey<T> {
17    /// Create a new `Grey` instance.
18    #[inline]
19    pub fn new(grey: T) -> Self {
20        debug_assert!(
21            !(grey < T::zero() || grey > T::one()),
22            "Grey component must be between 0 and 1."
23        );
24        Self { grey }
25    }
26
27    /// Get the `grey` component.
28    #[inline]
29    pub const fn grey(&self) -> T {
30        self.grey
31    }
32
33    /// Set the `grey` component.
34    #[inline]
35    pub fn set_grey(&mut self, grey: T) {
36        debug_assert!(
37            grey >= T::zero() && grey <= T::one(),
38            "Grey component must be between 0 and 1."
39        );
40        self.grey = grey;
41    }
42}