pub struct Rgba { /* private fields */ }Expand description
A floating-point RGBA color value.
- Each color component must have a nonnegative, non-NaN value. Depending on the application, they may be considered to have a nominal range of 0 to 1, or unbounded. (TODO: Split these use cases into different types.)
- The alpha must have a non-NaN value.
- Color components are linear (gamma = 1), but use the same RGB primaries as sRGB (Rec. 709).
- The alpha is not premultiplied.
- Alpha values less than zero and greater than one will usually be treated equivalently to zero and one, respectively, but are preserved rather than clipped.
§Suitability
The primary purpose of this color type and its relatives, and the reason for its enforced value restrictions, is to be able to be stored in game state data structures, with reliable comparison and serialization. It is not necessarily appropriate for storing the intermediate results of computations (though the operations do take care to avoid unnecessary re-validation).
Future versions of All is Cubes may choose to reduce the precision of this type to f16
when Rust has built-in support for that data type.
Implementations§
Source§impl Rgba
impl Rgba
Sourcepub const TRANSPARENT: Rgba
pub const TRANSPARENT: Rgba
Transparent black (all components zero); identical to
Rgba::new(0.0, 0.0, 0.0, 0.0) except for being a constant.
Sourcepub const BLACK: Rgba
pub const BLACK: Rgba
Black; identical to Rgba::new(0.0, 0.0, 0.0, 1.0) except for being a constant.
Sourcepub const WHITE: Rgba
pub const WHITE: Rgba
White; identical to Rgba::new(1.0, 1.0, 1.0, 1.0) except for being a constant.
Sourcepub const fn new(r: f32, g: f32, b: f32, a: f32) -> Rgba
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Rgba
Constructs a color from components. Panics if any component is NaN or negative. No other range checks are performed.
Sourcepub const fn new_ps(
r: PositiveSign<f32>,
g: PositiveSign<f32>,
b: PositiveSign<f32>,
alpha: ZeroOne<f32>,
) -> Rgba
pub const fn new_ps( r: PositiveSign<f32>, g: PositiveSign<f32>, b: PositiveSign<f32>, alpha: ZeroOne<f32>, ) -> Rgba
Constructs a color from components that have already been checked for not being NaN or negative.
Note: This exists primarily to assist the rgba_const! macro and may be renamed
or replaced in future versions.
Sourcepub const fn from_luminance(luminance: f32) -> Rgba
pub const fn from_luminance(luminance: f32) -> Rgba
Constructs a shade of gray (components all equal). Panics if any component is NaN. No other range checks are performed.
Sourcepub const fn red(self) -> PositiveSign<f32>
pub const fn red(self) -> PositiveSign<f32>
Returns the red color component. Values are linear (gamma = 1) and not premultiplied.
Sourcepub const fn green(self) -> PositiveSign<f32>
pub const fn green(self) -> PositiveSign<f32>
Returns the green color component. Values are linear (gamma = 1) and not premultiplied.
Sourcepub const fn blue(self) -> PositiveSign<f32>
pub const fn blue(self) -> PositiveSign<f32>
Returns the blue color component. Values are linear (gamma = 1) and not premultiplied.
Sourcepub const fn alpha(self) -> ZeroOne<f32>
pub const fn alpha(self) -> ZeroOne<f32>
Returns the alpha component.
Note that the RGB components are not premultiplied by alpha.
Sourcepub fn fully_transparent(self) -> bool
pub fn fully_transparent(self) -> bool
Returns whether this color is fully transparent, or has an alpha component of zero or less.
Sourcepub fn fully_opaque(self) -> bool
pub fn fully_opaque(self) -> bool
Returns whether this color is fully opaque, or has an alpha component of one or greater.
Sourcepub fn opacity_category(self) -> OpacityCategory
pub fn opacity_category(self) -> OpacityCategory
Returns the OpacityCategory which this color’s alpha fits into.
This returns the same information as Rgba::fully_transparent combined with
Rgba::fully_opaque.
Sourcepub const fn to_rgb(self) -> Rgb
pub const fn to_rgb(self) -> Rgb
Discards the alpha component to produce an RGB color.
Note that if alpha is 0 then the components could be any value and yet be “hidden” by the transparency.
Sourcepub fn map_rgb(self, f: impl FnOnce(Rgb) -> Rgb) -> Rgba
pub fn map_rgb(self, f: impl FnOnce(Rgb) -> Rgb) -> Rgba
Applies a function to the RGB portion of this color.
Sourcepub fn luminance(self) -> f32
pub fn luminance(self) -> f32
Combines the red, green, and blue components to obtain a luminance (“grayscale”) value. This will be equal to 1 if all components are 1.
This is identical to Rgb::luminance, ignoring the alpha component.
Sourcepub fn to_srgb8(self) -> [u8; 4]
pub fn to_srgb8(self) -> [u8; 4]
Converts this color lossily to sRGB 8-bits-per-component color.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Rgba
impl<'a> Arbitrary<'a> for Rgba
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Rgba, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Rgba, 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 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§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§impl From<(PositiveSign<f32>, PositiveSign<f32>, PositiveSign<f32>, ZeroOne<f32>)> for Rgba
impl From<(PositiveSign<f32>, PositiveSign<f32>, PositiveSign<f32>, ZeroOne<f32>)> for Rgba
Source§fn from(
value: (PositiveSign<f32>, PositiveSign<f32>, PositiveSign<f32>, ZeroOne<f32>),
) -> Rgba
fn from( value: (PositiveSign<f32>, PositiveSign<f32>, PositiveSign<f32>, ZeroOne<f32>), ) -> Rgba
Source§impl<'a> VoxelColor<'a> for Rgba
impl<'a> VoxelColor<'a> for Rgba
Source§fn into_blocks(self) -> VoxelBrush<'a>
fn into_blocks(self) -> VoxelBrush<'a>
VoxelBrush, the most general form of blocky drawing.impl Copy for Rgba
impl Eq for Rgba
impl StructuralPartialEq for Rgba
Auto Trait Implementations§
impl Freeze for Rgba
impl RefUnwindSafe for Rgba
impl Send for Rgba
impl Sync for Rgba
impl Unpin for Rgba
impl UnwindSafe for Rgba
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> 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> 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