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§

source

type Scalar

The type of the saturation modifier.

Required Methods§

source

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);
source

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);

Implementations on Foreign Types§

source§

impl<T> SaturateAssign for [T]
where T: SaturateAssign, T::Scalar: Clone,

§

type Scalar = <T as SaturateAssign>::Scalar

source§

fn saturate_assign(&mut self, factor: Self::Scalar)

source§

fn saturate_fixed_assign(&mut self, amount: Self::Scalar)

Implementors§

source§

impl<C: SaturateAssign> SaturateAssign for Alpha<C, C::Scalar>

source§

impl<S, T> SaturateAssign for Hsl<S, T>

§

type Scalar = T

source§

impl<S, T> SaturateAssign for Hsv<S, T>

§

type Scalar = T

source§

impl<T> SaturateAssign for Cam16UcsJmh<T>

§

type Scalar = T

source§

impl<T> SaturateAssign for Okhsl<T>

§

type Scalar = T

source§

impl<T> SaturateAssign for Okhsv<T>

§

type Scalar = T

source§

impl<Wp, T> SaturateAssign for Hsluv<Wp, T>

§

type Scalar = T

source§

impl<Wp, T> SaturateAssign for Lch<Wp, T>

§

type Scalar = T

source§

impl<Wp, T> SaturateAssign for Lchuv<Wp, T>

§

type Scalar = T