Module deltae::eq[][src]

Expand description

Tolerance and DeltaEq traits

This module deals with comparing two colors by DeltaE within a certain Tolerance.

See also: assert_delta_eq

Implementing Tolerance and DeltaEq

use deltae::*;

struct MyTolerance(f32);

impl Tolerance for MyTolerance {
    fn tolerance(self) -> f32 {
        self.0
    }
}

#[derive(Copy, Clone)]
struct MyLab(f32, f32, f32);

// Types that implement Into<Lab> also implement the Delta trait
impl From<MyLab> for LabValue {
    fn from(mylab: MyLab) -> LabValue {
        LabValue {
            l: mylab.0,
            a: mylab.1,
            b: mylab.2,
        }
    }
}

impl<D: Delta + Copy> DeltaEq<D> for MyLab {}

let mylab = MyLab(89.73, 1.88, -6.96);
let lab = LabValue::new(89.73, 1.88, -6.96).unwrap();
let de2000 = mylab.delta(lab, DEMethod::DE2000);
assert!(mylab.delta_eq(&lab, DE1976, 0.0));

Traits

DeltaEq

Trait to determine whether two values are within a certain tolerance of DeltaE. Types that implement Into<LabValue> implicitly implement Delta. Types that implement Delta and Copy may also implement DeltaEq for other types that also implement Delta and Copy.

Tolerance

Trait to define a tolerance value for the DeltaEq trait