pub trait SaturateAssign {
type Scalar;
// Required methods
fn saturate_assign(&mut self, factor: Self::Scalar);
fn saturate_fixed_assign(&mut self, amount: Self::Scalar);
}
Expand description
Assigning 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_assign
,
scales the saturation towards the maximum saturation value. This means that
for a color with 50% saturation, if saturate_assign(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_assign
, 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_assign(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 Saturate
, Desaturate
and DesaturateAssign
.
use approx::assert_relative_eq;
use palette::{Hsv, SaturateAssign};
let mut relative = Hsv::new_srgb(0.0, 0.5, 1.0);
relative.saturate_assign(0.5);
let mut fixed = Hsv::new_srgb(0.0, 0.5, 1.0);
fixed.saturate_fixed_assign(0.5);
assert_relative_eq!(relative.saturation, 0.75);
assert_relative_eq!(fixed.saturation, 1.0);
SaturateAssign
is also implemented for [T]
:
use palette::{Hsl, SaturateAssign};
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.saturate_assign(0.5);
my_array.saturate_assign(0.5);
my_slice.saturate_assign(0.5);
Required Associated Types§
Required Methods§
sourcefn saturate_assign(&mut self, factor: Self::Scalar)
fn saturate_assign(&mut self, factor: Self::Scalar)
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, SaturateAssign};
let mut color = Hsl::new_srgb(0.0, 0.5, 0.5);
color.saturate_assign(0.5);
assert_relative_eq!(color.saturation, 0.75);
sourcefn saturate_fixed_assign(&mut self, amount: Self::Scalar)
fn saturate_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::{Hsl, SaturateAssign};
let mut color = Hsl::new_srgb(0.0, 0.4, 0.5);
color.saturate_fixed_assign(0.2);
assert_relative_eq!(color.saturation, 0.6);