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> ZeroOne<T>where
T: FloatCore,
impl<T> ZeroOne<T>where
T: FloatCore,
Sourcepub const unsafe fn new_unchecked(value: T) -> ZeroOne<T>
pub const unsafe fn new_unchecked(value: T) -> ZeroOne<T>
Sourcepub const fn into_inner(self) -> T
pub const fn into_inner(self) -> T
Unwraps the value without modifying it.
Sourcepub fn complement(self) -> ZeroOne<T>
pub fn complement(self) -> ZeroOne<T>
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) -> ZeroOne<f32>
pub const fn new_strict(value: f32) -> ZeroOne<f32>
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) -> ZeroOne<f32>
pub const fn new_clamped(value: f32) -> ZeroOne<f32>
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) -> ZeroOne<f64>
pub const fn new_strict(value: f64) -> ZeroOne<f64>
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) -> ZeroOne<f64>
pub const fn new_clamped(value: f64) -> ZeroOne<f64>
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§
Source§impl<'a, T> Arbitrary<'a> for ZeroOne<T>
impl<'a, T> Arbitrary<'a> for ZeroOne<T>
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<ZeroOne<T>, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<ZeroOne<T>, Error>
Self from the given unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§impl<'de, T> Deserialize<'de> for ZeroOne<T>
impl<'de, T> Deserialize<'de> for ZeroOne<T>
Source§fn deserialize<D>(
deserializer: D,
) -> Result<ZeroOne<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<ZeroOne<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<T> Hash for ZeroOne<T>where
T: PrimitiveFloat,
impl<T> Hash for ZeroOne<T>where
T: PrimitiveFloat,
Source§impl<T> Mul<PositiveSign<T>> for ZeroOne<T>
impl<T> Mul<PositiveSign<T>> for ZeroOne<T>
Source§type Output = PositiveSign<T>
type Output = PositiveSign<T>
* operator.Source§fn mul(
self,
rhs: PositiveSign<T>,
) -> <ZeroOne<T> as Mul<PositiveSign<T>>>::Output
fn mul( self, rhs: PositiveSign<T>, ) -> <ZeroOne<T> as Mul<PositiveSign<T>>>::Output
* operation. Read moreSource§impl<T> Mul<ZeroOne<T>> for PositiveSign<T>
impl<T> Mul<ZeroOne<T>> for PositiveSign<T>
Source§impl<T> MulAssign for ZeroOne<T>
impl<T> MulAssign for ZeroOne<T>
Source§fn mul_assign(&mut self, rhs: ZeroOne<T>)
fn mul_assign(&mut self, rhs: ZeroOne<T>)
*= operation. Read moreSource§impl<T> Ord for ZeroOne<T>where
T: FloatCore + PartialOrd,
impl<T> Ord for ZeroOne<T>where
T: FloatCore + PartialOrd,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialOrd<T> for ZeroOne<T>where
T: PartialOrd,
impl<T> PartialOrd<T> for ZeroOne<T>where
T: PartialOrd,
Source§impl<T> PartialOrd for ZeroOne<T>where
T: FloatCore + PartialOrd,
impl<T> PartialOrd for ZeroOne<T>where
T: FloatCore + PartialOrd,
Source§impl<T> Serialize for ZeroOne<T>where
T: Serialize,
impl<T> Serialize for ZeroOne<T>where
T: Serialize,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl TryFrom<f32> for ZeroOne<f32>
impl TryFrom<f32> for ZeroOne<f32>
Source§fn try_from(
value: f32,
) -> Result<ZeroOne<f32>, <ZeroOne<f32> as TryFrom<f32>>::Error>
fn try_from( value: f32, ) -> Result<ZeroOne<f32>, <ZeroOne<f32> as TryFrom<f32>>::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>
Source§impl TryFrom<f64> for ZeroOne<f64>
impl TryFrom<f64> for ZeroOne<f64>
Source§fn try_from(
value: f64,
) -> Result<ZeroOne<f64>, <ZeroOne<f64> as TryFrom<f64>>::Error>
fn try_from( value: f64, ) -> Result<ZeroOne<f64>, <ZeroOne<f64> as TryFrom<f64>>::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>
impl<T> Copy for ZeroOne<T>where
T: Copy,
impl<T> Eq for ZeroOne<T>where
T: PartialEq,
impl<T> StructuralPartialEq for ZeroOne<T>
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> 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
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>,
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>
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
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more