Trait Clamp

Source
pub trait Clamp<Bound = Self>: Sized {
    // Required method
    fn clamped(self, lower: Bound, upper: Bound) -> Self;

    // Provided methods
    fn clamped_to_inclusive_range(self, range: RangeInclusive<Bound>) -> Self { ... }
    fn clamp(val: Self, lower: Bound, upper: Bound) -> Self { ... }
    fn clamp_to_inclusive_range(val: Self, range: RangeInclusive<Bound>) -> Self { ... }
    fn clamped01(self) -> Self
       where Bound: Zero + One { ... }
    fn clamp01(val: Self) -> Self
       where Bound: Zero + One { ... }
    fn clamped_minus1_1(self) -> Self
       where Bound: One + Neg<Output = Bound> { ... }
    fn clamp_minus1_1(val: Self) -> Self
       where Bound: One + Neg<Output = Bound> { ... }
}
Expand description

A scalar or vector that can be constrained to be between two values (inclusive).

Required Methods§

Source

fn clamped(self, lower: Bound, upper: Bound) -> Self

Constrains this value to be between lower and upper (inclusive).

§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§

Source

fn clamped_to_inclusive_range(self, range: RangeInclusive<Bound>) -> Self

Alias to clamped, which accepts a RangeInclusive parameter instead of two values.

Source

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.

Source

fn clamp_to_inclusive_range(val: Self, range: RangeInclusive<Bound>) -> Self

Alias to clamp, which accepts a RangeInclusive parameter instead of two values.

Source

fn clamped01(self) -> Self
where Bound: Zero + One,

Constrains this value to be between 0 and 1 (inclusive).

Source

fn clamp01(val: Self) -> Self
where Bound: Zero + One,

Alias to clamped01, which doesn’t take self.

Source

fn clamped_minus1_1(self) -> Self
where Bound: One + Neg<Output = Bound>,

Constrains this value to be between -1 and 1 (inclusive).

Source

fn clamp_minus1_1(val: Self) -> Self
where Bound: One + Neg<Output = Bound>,

Alias to clamped_minus1_1, which doesn’t take self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Clamp for f32

Source§

fn clamped(self, lower: f32, upper: f32) -> f32

Source§

impl Clamp for f64

Source§

fn clamped(self, lower: f64, upper: f64) -> f64

Source§

impl Clamp for i8

Source§

fn clamped(self, lower: i8, upper: i8) -> i8

Source§

impl Clamp for i16

Source§

fn clamped(self, lower: i16, upper: i16) -> i16

Source§

impl Clamp for i32

Source§

fn clamped(self, lower: i32, upper: i32) -> i32

Source§

impl Clamp for i64

Source§

fn clamped(self, lower: i64, upper: i64) -> i64

Source§

impl Clamp for isize

Source§

fn clamped(self, lower: isize, upper: isize) -> isize

Source§

impl Clamp for u8

Source§

fn clamped(self, lower: u8, upper: u8) -> u8

Source§

impl Clamp for u16

Source§

fn clamped(self, lower: u16, upper: u16) -> u16

Source§

impl Clamp for u32

Source§

fn clamped(self, lower: u32, upper: u32) -> u32

Source§

impl Clamp for u64

Source§

fn clamped(self, lower: u64, upper: u64) -> u64

Source§

impl Clamp for usize

Source§

fn clamped(self, lower: usize, upper: usize) -> usize

Source§

impl Clamp for Wrapping<i8>

Source§

fn clamped(self, lower: Wrapping<i8>, upper: Wrapping<i8>) -> Wrapping<i8>

Source§

impl Clamp for Wrapping<i16>

Source§

fn clamped(self, lower: Wrapping<i16>, upper: Wrapping<i16>) -> Wrapping<i16>

Source§

impl Clamp for Wrapping<i32>

Source§

fn clamped(self, lower: Wrapping<i32>, upper: Wrapping<i32>) -> Wrapping<i32>

Source§

impl Clamp for Wrapping<i64>

Source§

fn clamped(self, lower: Wrapping<i64>, upper: Wrapping<i64>) -> Wrapping<i64>

Source§

impl Clamp for Wrapping<isize>

Source§

fn clamped( self, lower: Wrapping<isize>, upper: Wrapping<isize>, ) -> Wrapping<isize>

Source§

impl Clamp for Wrapping<u8>

Source§

fn clamped(self, lower: Wrapping<u8>, upper: Wrapping<u8>) -> Wrapping<u8>

Source§

impl Clamp for Wrapping<u16>

Source§

fn clamped(self, lower: Wrapping<u16>, upper: Wrapping<u16>) -> Wrapping<u16>

Source§

impl Clamp for Wrapping<u32>

Source§

fn clamped(self, lower: Wrapping<u32>, upper: Wrapping<u32>) -> Wrapping<u32>

Source§

impl Clamp for Wrapping<u64>

Source§

fn clamped(self, lower: Wrapping<u64>, upper: Wrapping<u64>) -> Wrapping<u64>

Source§

impl Clamp for Wrapping<usize>

Source§

fn clamped( self, lower: Wrapping<usize>, upper: Wrapping<usize>, ) -> Wrapping<usize>

Implementors§

Source§

impl<T> Clamp for Extent2<T>
where T: Clamp,

Source§

impl<T> Clamp for Extent3<T>
where T: Clamp,

Source§

impl<T> Clamp for Rgb<T>
where T: Clamp,

Source§

impl<T> Clamp for Rgba<T>
where T: Clamp,

Source§

impl<T> Clamp for Vec2<T>
where T: Clamp,

Source§

impl<T> Clamp for Vec3<T>
where T: Clamp,

Source§

impl<T> Clamp for Vec4<T>
where T: Clamp,

Source§

impl<T> Clamp<T> for Extent2<T>
where T: Clamp + Copy,

Source§

impl<T> Clamp<T> for Extent3<T>
where T: Clamp + Copy,

Source§

impl<T> Clamp<T> for Rgb<T>
where T: Clamp + Copy,

Source§

impl<T> Clamp<T> for Rgba<T>
where T: Clamp + Copy,

Source§

impl<T> Clamp<T> for Vec2<T>
where T: Clamp + Copy,

Source§

impl<T> Clamp<T> for Vec3<T>
where T: Clamp + Copy,

Source§

impl<T> Clamp<T> for Vec4<T>
where T: Clamp + Copy,