pub trait Saturate {
type Scalar;
// Required methods
fn saturate(self, factor: Self::Scalar) -> Self;
fn saturate_fixed(self, amount: Self::Scalar) -> Self;
}Expand description
Operator for increasing the saturation (or chroma) of a color.
The trait’s functions are split into two groups of functions: relative and fixed/absolute.
The relative function, saturate, scales the
saturation towards the maximum saturation value. This means that for a color
with 50% saturation, if saturate(0.5) is applied to it, the color will
scale halfway to the maximum value of 100% resulting in a new saturation
value of 75%.
The fixed or absolute function,
saturate_fixed, increases the saturation by an
amount that is independent of the current saturation of the color. So for a
color with 50% saturation, if saturate_fixed(0.5) is applied to it, the
color will have 50% saturation added to its saturation value resulting in a
new value of 100%.
See also SaturateAssign, Desaturate and DesaturateAssign.
use approx::assert_relative_eq;
use palette::{Hsv, Saturate};
let a = Hsv::new_srgb(0.0, 0.5, 1.0);
assert_relative_eq!(a.saturate(0.5).saturation, 0.75);
assert_relative_eq!(a.saturate_fixed(0.5).saturation, 1.0);Required Associated Types§
Required Methods§
Sourcefn saturate(self, factor: Self::Scalar) -> Self
fn saturate(self, factor: Self::Scalar) -> Self
Scale the color towards the maximum saturation by factor, a value
ranging from 0.0 to 1.0.
use approx::assert_relative_eq;
use palette::{Hsl, Saturate};
let color = Hsl::new_srgb(0.0, 0.5, 0.5);
assert_relative_eq!(color.saturate(0.5).saturation, 0.75);Sourcefn saturate_fixed(self, amount: Self::Scalar) -> Self
fn saturate_fixed(self, amount: Self::Scalar) -> Self
Increase the saturation by amount, a value ranging from 0.0 to
1.0.
use approx::assert_relative_eq;
use palette::{Hsl, Saturate};
let color = Hsl::new_srgb(0.0, 0.4, 0.5);
assert_relative_eq!(color.saturate_fixed(0.2).saturation, 0.6);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.