Trait vek::ops::Clamp
[−]
[src]
pub trait Clamp<Bound = Self>: Sized { fn clamped(self, lower: Bound, upper: Bound) -> Self; fn clamp(val: Self, lower: Bound, upper: Bound) -> Self { ... } fn clamped01(self) -> Self
where
Bound: Zero + One, { ... } fn clamp01(val: Self) -> Self
where
Bound: Zero + One, { ... } }
A scalar or vector that can be constrained to be between two values (inclusive).
Required Methods
fn clamped(self, lower: Bound, upper: Bound) -> Self
Constrains this value to be between lower
and upper
(inclusive).
This would rather make use of inclusive ranges, but it's an unstable feature.
Panics
Panics if lower
is greater than upper
. Swap the values yourself if necessary.
use vek::ops::Clamp; assert_eq!(7.clamped(5, 10), 7); assert_eq!(4.clamped(5, 10), 5); assert_eq!(5.clamped(5, 10), 5); assert_eq!(10.clamped(5, 10), 10); assert_eq!(11.clamped(5, 10), 10);
Provided Methods
fn clamp(val: Self, lower: Bound, upper: Bound) -> Self
Alias to clamped
, which doesn't take self
.
Panics
Panics if lower
is greater than upper
. Swap the values yourself if necessary.
fn clamped01(self) -> Self where
Bound: Zero + One,
Bound: Zero + One,
Constrains this value to be between 0 and 1 (inclusive).
fn clamp01(val: Self) -> Self where
Bound: Zero + One,
Bound: Zero + One,
Alias to clamped01
, which doesn't take self
.
Implementations on Foreign Types
impl Clamp for f32
[src]
impl Clamp for f64
[src]
impl Clamp for i8
[src]
impl Clamp for i16
[src]
impl Clamp for i32
[src]
impl Clamp for i64
[src]
impl Clamp for isize
[src]
impl Clamp for u8
[src]
impl Clamp for u16
[src]
impl Clamp for u32
[src]
impl Clamp for u64
[src]
impl Clamp for usize
[src]
impl Clamp for Wrapping<i8>
[src]
impl Clamp for Wrapping<i16>
[src]
impl Clamp for Wrapping<i32>
[src]
impl Clamp for Wrapping<i64>
[src]
impl Clamp for Wrapping<isize>
[src]
impl Clamp for Wrapping<u8>
[src]
impl Clamp for Wrapping<u16>
[src]
impl Clamp for Wrapping<u32>
[src]
impl Clamp for Wrapping<u64>
[src]
impl Clamp for Wrapping<usize>
[src]
Implementors
impl<T: Clamp + Copy> Clamp<T> for Vec2<T>
impl<T: Clamp> Clamp<Vec2<T>> for Vec2<T>
impl<T: Clamp + Copy> Clamp<T> for Vec3<T>
impl<T: Clamp> Clamp<Vec3<T>> for Vec3<T>
impl<T: Clamp + Copy> Clamp<T> for Vec4<T>
impl<T: Clamp> Clamp<Vec4<T>> for Vec4<T>
impl<T: Clamp + Copy> Clamp<T> for Extent3<T>
impl<T: Clamp> Clamp<Extent3<T>> for Extent3<T>
impl<T: Clamp + Copy> Clamp<T> for Extent2<T>
impl<T: Clamp> Clamp<Extent2<T>> for Extent2<T>
impl<T: Clamp + Copy> Clamp<T> for Rgba<T>
impl<T: Clamp> Clamp<Rgba<T>> for Rgba<T>
impl<T: Clamp + Copy> Clamp<T> for Rgb<T>
impl<T: Clamp> Clamp<Rgb<T>> for Rgb<T>