pub trait DesaturateAssign {
type Scalar;
// Required methods
fn desaturate_assign(&mut self, factor: Self::Scalar);
fn desaturate_fixed_assign(&mut self, amount: Self::Scalar);
}
Expand description
Assigning operator for decreasing 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,
desaturate_assign
, scales the
saturation towards the minimum saturation value. This means that for a color
with 50% saturation, if desaturate_assign(0.5)
is applied to it, the color
will scale halfway to the minimum value of 0% resulting in a new saturation
value of 25%.
The fixed or absolute function,
desaturate_fixed_assign
,
decreases the saturation by an amount that is independent of the current
saturation of the color. So for a color with 50% saturation, if
desaturate_fixed_assign(0.5)
is applied to it, the color will have 50%
saturation removed from its saturation value resulting in a new value of 0%.
See also Desaturate
, Saturate
and SaturateAssign
.
use approx::assert_relative_eq;
use palette::{Hsv, DesaturateAssign};
let mut relative = Hsv::new_srgb(0.0, 0.5, 1.0);
relative.desaturate_assign(0.5);
let mut fixed = Hsv::new_srgb(0.0, 0.5, 1.0);
fixed.desaturate_fixed_assign(0.5);
assert_relative_eq!(relative.saturation, 0.25);
assert_relative_eq!(fixed.saturation, 0.0);
DesaturateAssign
is also implemented for [T]
:
use palette::{Hsl, DesaturateAssign};
let mut my_vec = vec![Hsl::new_srgb(104.0, 0.3, 0.8), Hsl::new_srgb(113.0, 0.5, 0.8)];
let mut my_array = [Hsl::new_srgb(104.0, 0.3, 0.8), Hsl::new_srgb(113.0, 0.5, 0.8)];
let mut my_slice = &mut [Hsl::new_srgb(104.0, 0.3, 0.8), Hsl::new_srgb(112.0, 0.5, 0.8)];
my_vec.desaturate_assign(0.5);
my_array.desaturate_assign(0.5);
my_slice.desaturate_assign(0.5);
Required Associated Types§
Required Methods§
sourcefn desaturate_assign(&mut self, factor: Self::Scalar)
fn desaturate_assign(&mut self, factor: Self::Scalar)
Scale the color towards the minimum saturation by factor
, a value
ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, DesaturateAssign};
let mut color = Hsv::new_srgb(0.0, 0.5, 0.5);
color.desaturate_assign(0.5);
assert_relative_eq!(color.saturation, 0.25);
sourcefn desaturate_fixed_assign(&mut self, amount: Self::Scalar)
fn desaturate_fixed_assign(&mut self, amount: Self::Scalar)
Increase the saturation by amount
, a value ranging from 0.0
to
1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, DesaturateAssign};
let mut color = Hsv::new_srgb(0.0, 0.4, 0.5);
color.desaturate_fixed_assign(0.2);
assert_relative_eq!(color.saturation, 0.2);