ZeroOne

Struct ZeroOne 

Source
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,

Source

pub const unsafe fn new_unchecked(value: T) -> ZeroOne<T>

Construct ZeroOne without checking the value.

§Safety

value must be +0, 1, or some value in between those two. Note that value >= 0. && value <= 1. is not a sufficient condition, because it does not exclude negative zero.

Source

pub const fn into_inner(self) -> T

Unwraps the value without modifying it.

Source

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<T> ZeroOne<T>

Source

pub const ZERO: ZeroOne<T>

The number zero, as a constant.

Source

pub const ONE: ZeroOne<T>

The number one, as a constant.

Source§

impl ZeroOne<f32>

Source

pub const fn new_strict(value: f32) -> ZeroOne<f32>

Wraps the given value in ZeroOne.

  • If value is in range, returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is out of range or NaN, panics.
Source

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

pub const fn is_zero(self) -> bool

Const version of self == ZeroOne::ZERO

Source

pub const fn is_one(self) -> bool

Const version of self == ZeroOne::ONE

Source§

impl ZeroOne<f64>

Source

pub const fn new_strict(value: f64) -> ZeroOne<f64>

Wraps the given value in ZeroOne.

  • If value is in range, returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is out of range or NaN, panics.
Source

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).
Source

pub const fn is_zero(self) -> bool

Const version of self == ZeroOne::ZERO

Source

pub const fn is_one(self) -> bool

Const version of self == ZeroOne::ONE

Trait Implementations§

Source§

impl<'a, T> Arbitrary<'a> for ZeroOne<T>
where T: FloatCore, NotNan<T>: Arbitrary<'a> + Neg<Output = NotNan<T>> + Copy, ZeroOne<T>: TryFrom<T>,

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<ZeroOne<T>, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

impl<T> AsRef<T> for ZeroOne<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Clone for ZeroOne<T>
where T: Clone,

Source§

fn clone(&self) -> ZeroOne<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> ConstOne for ZeroOne<T>
where T: FloatCore + ConstOne,

Source§

const ONE: ZeroOne<T>

The multiplicative identity element of Self, 1.
Source§

impl<T> Debug for ZeroOne<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for ZeroOne<T>
where T: FloatCore + Zero,

Source§

fn default() -> ZeroOne<T>

The default is zero, regardless of what T::default() is.

Source§

impl<'de, T> Deserialize<'de> for ZeroOne<T>
where T: Deserialize<'de>, ZeroOne<T>: TryFrom<T>, <ZeroOne<T> as TryFrom<T>>::Error: Error,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<ZeroOne<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for ZeroOne<T>
where T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<ZeroOne<f32>> for NotNan<f32>

Source§

fn from(value: ZeroOne<f32>) -> NotNan<f32>

Converts to this type from the input type.
Source§

impl From<ZeroOne<f32>> for PositiveSign<f32>

Source§

fn from(value: ZeroOne<f32>) -> PositiveSign<f32>

Converts to this type from the input type.
Source§

impl From<ZeroOne<f64>> for NotNan<f64>

Source§

fn from(value: ZeroOne<f64>) -> NotNan<f64>

Converts to this type from the input type.
Source§

impl From<ZeroOne<f64>> for PositiveSign<f64>

Source§

fn from(value: ZeroOne<f64>) -> PositiveSign<f64>

Converts to this type from the input type.
Source§

impl<T> From<bool> for ZeroOne<T>
where T: FloatCore,

Source§

fn from(value: bool) -> ZeroOne<T>

Converts to this type from the input type.
Source§

impl<T> Hash for ZeroOne<T>
where T: PrimitiveFloat,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Mul<PositiveSign<T>> for ZeroOne<T>
where T: FloatCore, PositiveSign<T>: From<ZeroOne<T>>,

Source§

type Output = PositiveSign<T>

The resulting type after applying the * operator.
Source§

fn mul( self, rhs: PositiveSign<T>, ) -> <ZeroOne<T> as Mul<PositiveSign<T>>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul<ZeroOne<T>> for PositiveSign<T>
where T: FloatCore, PositiveSign<T>: From<ZeroOne<T>>,

Source§

type Output = PositiveSign<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ZeroOne<T>) -> <PositiveSign<T> as Mul<ZeroOne<T>>>::Output

Performs the * operation. Read more
Source§

impl Mul<ZeroOne<f32>> for Rgb

Source§

fn mul(self, scalar: ZeroOne<f32>) -> Rgb

Multiplies this color value by a scalar.

Source§

type Output = Rgb

The resulting type after applying the * operator.
Source§

impl Mul<ZeroOne<f32>> for Rgb01

Source§

fn mul(self, scalar: ZeroOne<f32>) -> Rgb01

Multiplies this color value by a scalar.

Source§

type Output = Rgb01

The resulting type after applying the * operator.
Source§

impl<T> Mul for ZeroOne<T>
where T: FloatCore<Output = T> + Mul,

Source§

type Output = ZeroOne<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ZeroOne<T>) -> <ZeroOne<T> as Mul>::Output

Performs the * operation. Read more
Source§

impl<T> MulAssign for ZeroOne<T>
where T: FloatCore<Output = T> + Mul,

Source§

fn mul_assign(&mut self, rhs: ZeroOne<T>)

Performs the *= operation. Read more
Source§

impl<T> One for ZeroOne<T>
where T: FloatCore + One,

Source§

fn one() -> ZeroOne<T>

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<T> Ord for ZeroOne<T>
where T: FloatCore + PartialOrd,

Source§

fn cmp(&self, other: &ZeroOne<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq<T> for ZeroOne<T>
where T: PartialEq,

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq for ZeroOne<T>
where T: PartialEq,

Source§

fn eq(&self, other: &ZeroOne<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd for ZeroOne<T>
where T: FloatCore + PartialOrd,

Source§

fn partial_cmp(&self, other: &ZeroOne<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<f32> for ZeroOne<f32>

Source§

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 and value ≤ 1, returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is out of range or NaN, returns an error.
Source§

type Error = NotZeroOne<f32>

The type returned in the event of a conversion error.
Source§

impl TryFrom<f64> for ZeroOne<f64>

Source§

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 and value ≤ 1, returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is out of range or NaN, returns an error.
Source§

type Error = NotZeroOne<f64>

The type returned in the event of a conversion error.
Source§

impl<T> Copy for ZeroOne<T>
where T: Copy,

Source§

impl<T> Eq for ZeroOne<T>
where T: PartialEq,

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> One for T
where T: One,

Source§

fn one() -> T

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,