Trait geng::prelude::Clamp

pub trait Clamp: Sized + PartialOrd {
    // Provided methods
    fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Self
       where Self: Clone { ... }
    fn clamp_abs(self, max: Self) -> Self
       where Self: Neg<Output = Self> + Copy { ... }
    fn clamp_max(self, max: Self) -> Self { ... }
    fn clamp_min(self, min: Self) -> Self { ... }
}
Expand description

Provides methods for clamping values

Provided Methods§

fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Self
where Self: Clone,

Clamps a value in range.

§Examples
assert_eq!(2.0.clamp_range(0.0..=1.0), 1.0);
assert_eq!(2.0.clamp_range(3.0..), 3.0);
assert_eq!(2.0.clamp_range(..=0.0), 0.0);

fn clamp_abs(self, max: Self) -> Self
where Self: Neg<Output = Self> + Copy,

Clamp the absolute value. Same as self.clamp_range(-max..=max)

fn clamp_max(self, max: Self) -> Self

Clamp by maximum value

If self is greater than max then return max, otherwise return self

fn clamp_min(self, min: Self) -> Self

Clamp by minimum value

If self is less than min then return min, otherwise return self

Object Safety§

This trait is not object safe.

Implementors§

§

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