From b93c39873e9c72de5ba2f9884c5e9296c9f27a4c Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Mon, 11 Nov 2024 16:08:40 +0100 Subject: [PATCH] Simplify `OpaqueColor::difference` as in `AlphaColor:difference` Also add #[must_use]. --- color/src/color.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/color/src/color.rs b/color/src/color.rs index b7e657b..da4f0ce 100644 --- a/color/src/color.rs +++ b/color/src/color.rs @@ -156,11 +156,10 @@ impl OpaqueColor { } /// Difference between two colors by Euclidean metric. + #[must_use] pub fn difference(self, other: Self) -> f32 { - let x = self.components; - let y = other.components; - let (d0, d1, d2) = (x[0] - y[0], x[1] - y[1], x[2] - y[2]); - (d0 * d0 + d1 * d1 + d2 * d2).sqrt() + let d = (self - other).components; + (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt() } /// Linearly interpolate colors, without hue fixup.