pub struct ZeroOne<T>(/* private fields */);Expand description
A floating-point number which is within the range +0 to +1 (inclusive).
This may be used for alpha blending, reflectance, lerps, and anything else where values outside the range 0 to 1 is meaningless. It is closed under multiplication.
Because NaN and negative zero are excluded, this type implements Eq straightforwardly,
and can reliably be used as a map key for caching, interning, etc.
Implementations§
Source§impl<T: FloatCore> ZeroOne<T>
impl<T: FloatCore> ZeroOne<T>
Sourcepub const unsafe fn new_unchecked(value: T) -> Self
pub const unsafe fn new_unchecked(value: T) -> Self
Sourcepub const fn into_inner(self) -> T
pub const fn into_inner(self) -> T
Unwraps the value without modifying it.
Sourcepub fn complement(self) -> Self
pub fn complement(self) -> Self
Returns 1.0 - self.
The result cannot be out of range, so this operation is always successful.
Source§impl ZeroOne<f32>
impl ZeroOne<f32>
Sourcepub const fn new_strict(value: f32) -> Self
pub const fn new_strict(value: f32) -> Self
Wraps the given value in ZeroOne.
- If
valueis in range, returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis out of range or NaN, panics.
Sourcepub const fn new_clamped(value: f32) -> Self
pub const fn new_clamped(value: f32) -> Self
Wraps the given value in ZeroOne.
- If the value is NaN, panics.
- If the value is out of range, replaces it with the nearest in-range value (0 or 1).
Source§impl ZeroOne<f64>
impl ZeroOne<f64>
Sourcepub const fn new_strict(value: f64) -> Self
pub const fn new_strict(value: f64) -> Self
Wraps the given value in ZeroOne.
- If
valueis in range, returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis out of range or NaN, panics.
Sourcepub const fn new_clamped(value: f64) -> Self
pub const fn new_clamped(value: f64) -> Self
Wraps the given value in ZeroOne.
- If the value is NaN, panics.
- If the value is out of range, replaces it with the nearest in-range value (0 or 1).
Trait Implementations§
impl<T: Copy> Copy for ZeroOne<T>
impl<T: PartialEq> Eq for ZeroOne<T>
Source§impl<T: PrimitiveFloat> Hash for ZeroOne<T>
impl<T: PrimitiveFloat> Hash for ZeroOne<T>
Source§impl<T: FloatCore> Mul<PositiveSign<T>> for ZeroOne<T>
impl<T: FloatCore> Mul<PositiveSign<T>> for ZeroOne<T>
Source§type Output = PositiveSign<T>
type Output = PositiveSign<T>
The resulting type after applying the
* operator.Source§impl<T: FloatCore + Mul<Output = T>> MulAssign for ZeroOne<T>
impl<T: FloatCore + Mul<Output = T>> MulAssign for ZeroOne<T>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moreSource§impl<T: FloatCore + PartialOrd> Ord for ZeroOne<T>
impl<T: FloatCore + PartialOrd> Ord for ZeroOne<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq> PartialEq for ZeroOne<T>
impl<T: PartialEq> PartialEq for ZeroOne<T>
Source§impl<T: FloatCore + PartialOrd> PartialOrd for ZeroOne<T>
impl<T: FloatCore + PartialOrd> PartialOrd for ZeroOne<T>
Source§impl<T: PartialOrd> PartialOrd<T> for ZeroOne<T>
impl<T: PartialOrd> PartialOrd<T> for ZeroOne<T>
impl<T> StructuralPartialEq for ZeroOne<T>
Source§impl TryFrom<f32> for ZeroOne<f32>
impl TryFrom<f32> for ZeroOne<f32>
Source§fn try_from(value: f32) -> Result<Self, Self::Error>
fn try_from(value: f32) -> Result<Self, Self::Error>
Checks that value is within the range 0 to 1.
- If
value> 0 andvalue≤ 1, returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis out of range or NaN, returns an error.
Source§type Error = NotZeroOne<f32>
type Error = NotZeroOne<f32>
The type returned in the event of a conversion error.
Source§impl TryFrom<f64> for ZeroOne<f64>
impl TryFrom<f64> for ZeroOne<f64>
Source§fn try_from(value: f64) -> Result<Self, Self::Error>
fn try_from(value: f64) -> Result<Self, Self::Error>
Checks that value is within the range 0 to 1.
- If
value> 0 andvalue≤ 1, returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis out of range or NaN, returns an error.
Source§type Error = NotZeroOne<f64>
type Error = NotZeroOne<f64>
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl<T> Freeze for ZeroOne<T>where
T: Freeze,
impl<T> RefUnwindSafe for ZeroOne<T>where
T: RefUnwindSafe,
impl<T> Send for ZeroOne<T>where
T: Send,
impl<T> Sync for ZeroOne<T>where
T: Sync,
impl<T> Unpin for ZeroOne<T>where
T: Unpin,
impl<T> UnsafeUnpin for ZeroOne<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ZeroOne<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.