Trait palette::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));

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: Stimulus + Clamp,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<T> Clamp for Okhwb<T>where T: Real + Stimulus + One + Clamp + PartialCmp + Add<Output = T> + DivAssign + Clone, T::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: Zero + Real + Clamp,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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