use nalgebra::Vector2;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Chromaticity {
xy: Vector2<f64>,
}
impl Chromaticity {
pub const fn new(x: f64, y: f64) -> Self {
let xy = Vector2::new(x, y);
Self { xy }
}
pub fn x(self) -> f64 {
self.xy.x
}
pub fn y(self) -> f64 {
self.xy.y
}
pub fn to_array(self) -> [f64; 2] {
*self.xy.as_ref()
}
pub const fn to_vector(self) -> Vector2<f64> {
self.xy
}
pub fn to_tuple(&self) -> (f64, f64) {
(self.xy.x, self.xy.y)
}
}
impl Default for Chromaticity {
fn default() -> Self {
Self::new(1.0 / 3.0, 1.0 / 3.0)
}
}