diff options
Diffstat (limited to 'evc/src/pixel.rs')
-rw-r--r-- | evc/src/pixel.rs | 11 |
1 files changed, 11 insertions, 0 deletions
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() + } +} |