palette

Trait IsWithinBounds

source
pub trait IsWithinBounds: HasBoolMask {
    // Required method
    fn is_within_bounds(&self) -> Self::Mask;
}
Expand description

Checks if color components are within their expected range bounds.

A color with out-of-bounds components may be clamped with Clamp or ClampAssign.

use palette::{Srgb, IsWithinBounds};
let a = Srgb::new(0.4f32, 0.3, 0.8);
let b = Srgb::new(1.2f32, 0.3, 0.8);
let c = Srgb::new(-0.6f32, 0.3, 0.8);

assert!(a.is_within_bounds());
assert!(!b.is_within_bounds());
assert!(!c.is_within_bounds());

IsWithinBounds is also implemented for [T]:

use palette::{Srgb, IsWithinBounds};

let my_vec = vec![Srgb::new(0.4f32, 0.3, 0.8), Srgb::new(0.8, 0.5, 0.1)];
let my_array = [Srgb::new(0.4f32, 0.3, 0.8), Srgb::new(1.3, 0.5, -3.0)];
let my_slice = &[Srgb::new(0.4f32, 0.3, 0.8), Srgb::new(1.2, 0.3, 0.8)];

assert!(my_vec.is_within_bounds());
assert!(!my_array.is_within_bounds());
assert!(!my_slice.is_within_bounds());

Required Methods§

source

fn is_within_bounds(&self) -> Self::Mask

Check if the color’s components are within the expected range bounds.

use palette::{Srgb, IsWithinBounds};
assert!(Srgb::new(0.8f32, 0.5, 0.2).is_within_bounds());
assert!(!Srgb::new(1.3f32, 0.5, -3.0).is_within_bounds());

Implementations on Foreign Types§

source§

impl<T> IsWithinBounds for [T]

source§

fn is_within_bounds(&self) -> Self::Mask

Implementors§

source§

impl<C, T> IsWithinBounds for Alpha<C, T>
where C: IsWithinBounds, T: Stimulus + PartialCmp + IsWithinBounds<Mask = C::Mask>, C::Mask: BitAnd<Output = C::Mask>,

source§

impl<S, T> IsWithinBounds for Luma<S, T>
where T: PartialCmp + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<S, T> IsWithinBounds for Rgb<S, T>
where T: PartialCmp + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<S, T> IsWithinBounds for Hsl<S, T>
where T: PartialCmp + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<S, T> IsWithinBounds for Hsv<S, T>
where T: PartialCmp + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<S, T> IsWithinBounds for Hwb<S, T>
where T: PartialCmp + Add<Output = T> + Clone + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16Jch<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16Jmh<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16Jsh<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16Qch<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16Qmh<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16Qsh<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16<T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16UcsJab<T>
where T: PartialCmp + Real + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Cam16UcsJmh<T>
where T: PartialCmp + Zero + Real, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Okhsl<T>
where T: PartialCmp + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Okhsv<T>
where T: PartialCmp + Real + Arithmetics + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Okhwb<T>
where T: PartialCmp + Add<Output = T> + Clone + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Oklab<T>
where T: PartialCmp + Zero + One, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<T> IsWithinBounds for Oklch<T>
where T: PartialCmp + Zero + One, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<Wp, T> IsWithinBounds for Hsluv<Wp, T>
where T: PartialCmp + Real + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<Wp, T> IsWithinBounds for Lab<Wp, T>
where T: PartialCmp + Real + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<Wp, T> IsWithinBounds for Lch<Wp, T>
where T: PartialCmp + Real + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<Wp, T> IsWithinBounds for Lchuv<Wp, T>
where T: PartialCmp + Real + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<Wp, T> IsWithinBounds for Luv<Wp, T>
where T: PartialCmp + Real + Zero, T::Mask: BitAnd<Output = T::Mask>,

source§

impl<Wp, T> IsWithinBounds for Xyz<Wp, T>
where T: PartialCmp + Zero, T::Mask: BitAnd<Output = T::Mask>, Wp: WhitePoint<T>,

source§

impl<Wp, T> IsWithinBounds for Yxy<Wp, T>
where T: PartialCmp + Zero + One, T::Mask: BitAnd<Output = T::Mask>,