1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::convert::{GetChroma, GetHue};
use angle::{Angle, FromAngle, Rad};
use num_traits;
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Hash)]
pub struct ChromaticityCoordinates<T> {
pub alpha: T,
pub beta: T,
}
impl<T> ChromaticityCoordinates<T>
where
T: num_traits::Float,
{
pub fn new(alpha: T, beta: T) -> Self {
ChromaticityCoordinates { alpha, beta }
}
}
impl<T> Default for ChromaticityCoordinates<T>
where
T: num_traits::Float,
{
fn default() -> Self {
ChromaticityCoordinates {
alpha: T::zero(),
beta: T::zero(),
}
}
}
impl<T> GetChroma for ChromaticityCoordinates<T>
where
T: num_traits::Float,
{
type ChromaType = T;
fn get_chroma(&self) -> Self::ChromaType {
(self.alpha * self.alpha + self.beta * self.beta).sqrt()
}
}
impl<T> GetHue for ChromaticityCoordinates<T>
where
T: num_traits::Float,
{
type InternalAngle = Rad<T>;
fn get_hue<U>(&self) -> U
where
U: Angle<Scalar = <Self::InternalAngle as Angle>::Scalar> + FromAngle<Self::InternalAngle>,
{
U::atan2(self.beta, self.alpha)
}
}