use super::{LinearSrgb, Oklab};
use num_traits::Euclid;
#[allow(unused_imports)]
use num_traits::Float;
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Okhsv {
pub h: f32,
pub s: f32,
pub v: f32,
}
impl Okhsv {
pub fn new(h: f32, s: f32, v: f32) -> Self {
Okhsv {
h: Euclid::rem_euclid(&h, &1.),
s: s.clamp(0., 1.),
v: v.clamp(0., 1.),
}
}
pub fn to_oklab(&self) -> Oklab {
let v = self.v;
let max_c = 0.4 * v;
let c = self.s * max_c;
let angle = 2.0 * core::f32::consts::PI * self.h;
let a = c * angle.cos();
let b = c * angle.sin();
Oklab { l: v, a, b }
}
pub fn to_linear_srgb(&self) -> LinearSrgb {
self.to_oklab().to_linear_srgb()
}
}