Trait palette::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§
sourcefn is_within_bounds(&self) -> Self::Mask
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());