Trait palette::color_difference::EuclideanDistance

source ·
pub trait EuclideanDistance: Sized {
    type Scalar;

    // Required method
    fn distance_squared(self, other: Self) -> Self::Scalar;

    // Provided method
    fn distance(self, other: Self) -> Self::Scalar
       where Self::Scalar: Sqrt { ... }
}
Expand description

Calculate the distance between two colors as if they were coordinates in Euclidean space.

Euclidean distance is not always a good measurement of visual color difference, depending on the color space. Some spaces, like Lab and Oklab, will give a fairly uniform result, while other spaces, such as Rgb, will give much less uniform results. Despite that, it’s still appropriate for some applications.

Required Associated Types§

source

type Scalar

The type for the distance value.

Required Methods§

source

fn distance_squared(self, other: Self) -> Self::Scalar

Calculate the squared Euclidean distance from self to other.

This is typically a faster option than Self::distance for some cases, such as when comparing two distances.

Provided Methods§

source

fn distance(self, other: Self) -> Self::Scalar
where Self::Scalar: Sqrt,

Calculate the Euclidean distance from self to other.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<S, T> EuclideanDistance for Luma<S, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<S, T> EuclideanDistance for Rgb<S, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<T> EuclideanDistance for Cam16UcsJab<T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<T> EuclideanDistance for Oklab<T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<Wp, T> EuclideanDistance for Lab<Wp, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<Wp, T> EuclideanDistance for Luv<Wp, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<Wp, T> EuclideanDistance for Xyz<Wp, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

source§

impl<Wp, T> EuclideanDistance for Yxy<Wp, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T