Skip to content

Commit

Permalink
chore: add chromaticity() helper for XYZ
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther committed Oct 11, 2023
1 parent 59b1c7f commit b811483
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clovers/src/colors/xyz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ impl XYZ_Tristimulus {
pub fn is_finite(&self) -> bool {
self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
}

/// Returns the cromaticity tuple `(x,y)` by scaling the `X` and `Y` appropriately to unity brightness.
#[must_use]
pub fn chromaticity(&self) -> (Float, Float) {
let &Self { x, y, z } = self;
let chroma_x = x / (x + y + z);
let chroma_y = y / (x + y + z);
(chroma_x, chroma_y)
}
}

impl Mul<Float> for XYZ_Normalized {
Expand Down

0 comments on commit b811483

Please sign in to comment.