mod conversions;
#[cfg(test)]
mod tests;
#[derive(Debug, Clone, Copy)]
pub struct Cielch(f32, f32, f32);
impl Cielch {
pub fn new(lightness: f32, chroma: f32, hue: f32) -> Option<Self> {
match (0f32..=100f32).contains(&lightness) {
true => Some(Self(lightness, chroma, hue)),
false => None,
}
}
pub fn lightness(&self) -> f32 {
self.0
}
pub fn chroma(&self) -> f32 {
self.1
}
pub fn hue(&self) -> f32 {
self.2
}
}
impl PartialEq for Cielch {
fn eq(&self, other: &Self) -> bool {
let lhs = [self.lightness(), self.chroma(), self.hue()];
let rhs = [other.lightness(), other.chroma(), other.hue()];
match self.chroma() != 0f32 || other.chroma() != 0f32 {
true => (0..3).all(|x| lhs[x] == rhs[x]),
false => self.lightness() == other.lightness(),
}
}
}