cosmic::cosmic_theme::palette

Trait Clamp

source
pub trait Clamp {
    // Required method
    fn clamp(self) -> Self;
}
Expand description

An operator for restricting a color’s components to their expected ranges.

IsWithinBounds can be used to check if the components are within their range bounds.

See also ClampAssign.

use palette::{Srgb, IsWithinBounds, Clamp};

let unclamped = Srgb::new(1.3f32, 0.5, -3.0);
assert!(!unclamped.is_within_bounds());

let clamped = unclamped.clamp();
assert!(clamped.is_within_bounds());
assert_eq!(clamped, Srgb::new(1.0, 0.5, 0.0));

Required Methods§

source

fn clamp(self) -> Self

Return a new color where out-of-bounds components have been changed to the nearest valid values.

use palette::{Srgb, Clamp};
assert_eq!(Srgb::new(1.3, 0.5, -3.0).clamp(), Srgb::new(1.0, 0.5, 0.0));

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<C, T> Clamp for Alpha<C, T>
where C: Clamp, T: Stimulus + Clamp,

source§

impl<S, T> Clamp for Luma<S, T>
where T: Clamp + Stimulus,

source§

impl<S, T> Clamp for Rgb<S, T>
where T: Clamp + Stimulus,

source§

impl<S, T> Clamp for Hsl<S, T>
where T: Clamp + Stimulus,

source§

impl<S, T> Clamp for Hsv<S, T>
where T: Clamp + Stimulus,

source§

impl<S, T> Clamp for Hwb<S, T>
where T: One + Clamp + PartialCmp + Add<Output = T> + DivAssign + Clone + Stimulus, <T as HasBoolMask>::Mask: Select<T>,

source§

impl<T> Clamp for Cam16Jch<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16Jmh<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16Jsh<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16Qch<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16Qmh<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16Qsh<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16<T>
where T: Clamp + Zero,

source§

impl<T> Clamp for Cam16UcsJab<T>
where T: Clamp + Real + Zero,

source§

impl<T> Clamp for Cam16UcsJmh<T>
where T: Clamp + Zero + Real,

source§

impl<T> Clamp for Okhsl<T>
where T: Clamp + Stimulus,

source§

impl<T> Clamp for Okhsv<T>
where T: Clamp + Real + Arithmetics + Stimulus,

source§

impl<T> Clamp for Okhwb<T>
where T: One + Clamp + PartialCmp + Add<Output = T> + DivAssign + Clone + Stimulus, <T as HasBoolMask>::Mask: Select<T>,

source§

impl<T> Clamp for Oklab<T>
where T: Clamp + Zero + One,

source§

impl<T> Clamp for Oklch<T>
where T: Clamp + Zero + One,

source§

impl<Wp, T> Clamp for Hsluv<Wp, T>
where T: Clamp + Real + Zero,

source§

impl<Wp, T> Clamp for Lab<Wp, T>
where T: Clamp + Real + Zero,

source§

impl<Wp, T> Clamp for Lch<Wp, T>
where T: Clamp + Real + Zero,

source§

impl<Wp, T> Clamp for Lchuv<Wp, T>
where T: Clamp + Real + Zero,

source§

impl<Wp, T> Clamp for Luv<Wp, T>
where T: Clamp + Real + Zero,

source§

impl<Wp, T> Clamp for Xyz<Wp, T>
where T: Clamp + Zero, Wp: WhitePoint<T>,

source§

impl<Wp, T> Clamp for Yxy<Wp, T>
where T: Clamp + Zero + One,