use crate::{Colour, Component, DefinedGamut};
#[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 CieXyz<T>([T; 0x3]);
impl<T: Component> CieXyz<T> {
#[inline(always)]
#[must_use]
pub const fn new(x: T, y: T, z: T) -> Self {
let data = [x, y, z];
Self(data)
}
#[inline]
#[must_use]
pub fn map<U, F>(self, mut op: F) -> CieXyz<U>
where
U: Component,
F: FnMut(T) -> U,
{
let (x, y, z) = self.get();
let x = op(x);
let y = op(y);
let z = op(z);
CieXyz::new(x, y, z)
}
#[inline(always)]
#[must_use]
pub const fn get(self) -> (T, T, T) {
let [x, y, z] = self.0;
(x, y, z)
}
}
impl<T: Component> Colour for CieXyz<T> { }
impl<T: Component> DefinedGamut for CieXyz<T> { }