From 4b12b320d48abf90a6f524a226604ad738e5684f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 5 Dec 2022 22:27:49 +0100 Subject: even more code --- evc/src/pixel.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'evc/src/pixel.rs') diff --git a/evc/src/pixel.rs b/evc/src/pixel.rs index adeaf84..559dedc 100644 --- a/evc/src/pixel.rs +++ b/evc/src/pixel.rs @@ -17,3 +17,14 @@ impl Ser for Pixel { Ok(Self { r, g, b }) } } + +impl Pixel { + pub fn distance(a: Pixel, b: Pixel) -> f64 { + let (rd, gd, bd) = ( + a.r.abs_diff(b.r) as f64, + a.r.abs_diff(b.r) as f64, + a.r.abs_diff(b.r) as f64, + ); + (rd * rd + gd * gd + bd * bd).sqrt() + } +} -- cgit v1.2.3-70-g09d2