use crate::{BalancedColour, Colour, Component};
#[cfg(feature = "bytemuck")]
use bytemuck::{Pod, Zeroable};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "zerocopy")]
use zerocopy::{FromZeros, Immutable, IntoBytes};
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "bytemuck", derive(Pod, Zeroable))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "zerocopy", derive(FromZeros, Immutable, IntoBytes))]
pub struct Hwb<T>([T; 0x3]);
impl<T: Component> Hwb<T> {
#[inline(always)]
#[must_use]
pub const fn new(hue: T, whiteness: T, blackness: T) -> Self {
let data = [hue, whiteness, blackness];
Self(data)
}
#[inline]
#[must_use]
pub fn map<U, F>(self, mut op: F) -> Hwb<U>
where
U: Component,
F: FnMut(T) -> U,
{
let (hue, whiteness, blackness) = self.get();
let hue = op(hue);
let whiteness = op(whiteness);
let blackness = op(blackness);
Hwb::new(hue, whiteness, blackness)
}
#[inline(always)]
#[must_use]
pub const fn get(self) -> (T, T, T) {
let [hue, whiteness, blackness] = self.0;
(hue, whiteness, blackness)
}
}
unsafe impl<T: Component> BalancedColour for Hwb<T> {
type Component = T;
}
impl<T: Component> Colour for Hwb<T> { }