#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub struct Hwba {
hue: f64,
w: f64,
b: f64,
alpha: f64,
}
impl Hwba {
pub fn new(hue: f64, w: f64, b: f64, alpha: f64) -> Self {
let wbsum = w + b;
let (w, b) = if wbsum > 1. {
(w / wbsum, b / wbsum)
} else {
(w, b)
};
let alpha = alpha.clamp(0., 1.);
Self { hue, w, b, alpha }
}
pub fn hue(&self) -> f64 {
self.hue
}
pub fn whiteness(&self) -> f64 {
self.w
}
pub fn blackness(&self) -> f64 {
self.b
}
pub fn alpha(&self) -> f64 {
self.alpha
}
pub fn set_alpha(&mut self, alpha: f64) {
self.alpha = alpha.clamp(0., 1.);
}
}