| 1 | use crate::{LCh, Lab}; |
| 2 | use approx::{AbsDiffEq, RelativeEq}; |
| 3 | |
| 4 | impl AbsDiffEq<Lab> for Lab { |
| 5 | type Epsilon = f32; |
| 6 | |
| 7 | fn default_epsilon() -> Self::Epsilon { |
| 8 | std::f32::EPSILON |
| 9 | } |
| 10 | |
| 11 | fn abs_diff_eq(&self, other: &Lab, epsilon: Self::Epsilon) -> bool { |
| 12 | AbsDiffEq::abs_diff_eq(&self.l, &other.l, epsilon) |
| 13 | && AbsDiffEq::abs_diff_eq(&self.a, &other.a, epsilon) |
| 14 | && AbsDiffEq::abs_diff_eq(&self.b, &other.b, epsilon) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | impl RelativeEq<Lab> for Lab { |
| 19 | fn default_max_relative() -> Self::Epsilon { |
| 20 | std::f32::EPSILON |
| 21 | } |
| 22 | |
| 23 | fn relative_eq( |
| 24 | &self, |
| 25 | other: &Lab, |
| 26 | epsilon: Self::Epsilon, |
| 27 | max_relative: Self::Epsilon, |
| 28 | ) -> bool { |
| 29 | RelativeEq::relative_eq(&self.l, &other.l, epsilon, max_relative) |
| 30 | && RelativeEq::relative_eq(&self.a, &other.a, epsilon, max_relative) |
| 31 | && RelativeEq::relative_eq(&self.b, &other.b, epsilon, max_relative) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | impl AbsDiffEq<LCh> for LCh { |
| 36 | type Epsilon = f32; |
| 37 | |
| 38 | fn default_epsilon() -> Self::Epsilon { |
| 39 | std::f32::EPSILON |
| 40 | } |
| 41 | |
| 42 | fn abs_diff_eq(&self, other: &LCh, epsilon: Self::Epsilon) -> bool { |
| 43 | AbsDiffEq::abs_diff_eq(&self.l, &other.l, epsilon) |
| 44 | && AbsDiffEq::abs_diff_eq(&self.c, &other.c, epsilon) |
| 45 | && AbsDiffEq::abs_diff_eq(&self.h, &other.h, epsilon) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl RelativeEq<LCh> for LCh { |
| 50 | fn default_max_relative() -> Self::Epsilon { |
| 51 | std::f32::EPSILON |
| 52 | } |
| 53 | |
| 54 | fn relative_eq( |
| 55 | &self, |
| 56 | other: &LCh, |
| 57 | epsilon: Self::Epsilon, |
| 58 | max_relative: Self::Epsilon, |
| 59 | ) -> bool { |
| 60 | RelativeEq::relative_eq(&self.l, &other.l, epsilon, max_relative) |
| 61 | && RelativeEq::relative_eq(&self.c, &other.c, epsilon, max_relative) |
| 62 | && RelativeEq::relative_eq(&self.h, &other.h, epsilon, max_relative) |
| 63 | } |
| 64 | } |