colorsys/common/
approx.rs1use crate::common::f64_abs;
2use crate::units::GetColorUnits;
3
4pub static DEFAULT_APPROX_EQ_PRECISION: f64 = 1e-9;
7
8pub trait ApproxEq<T> {
10 fn approx_eq(&self, other: &T) -> bool;
11 fn approx_eq_clarify(&self, other: &T, precision: f64) -> bool;
12}
13
14pub fn approx(x: f64, y: f64, precision: f64) -> bool {
15 f64_abs(x - y) < precision
16}
17
18impl<T> ApproxEq<T> for T where T: GetColorUnits {
19 fn approx_eq(&self, other: &T) -> bool {
20 self.get_units().approx_eq(other.get_units())
21 }
22 fn approx_eq_clarify(&self, other: &T, precision: f64) -> bool {
23 self.get_units().approx_eq_clarify(other.get_units(), precision)
24 }
25}