Struct all_is_cubes::math::Rgba
source · pub struct Rgba { /* private fields */ }
Expand description
A floating-point RGBA color value.
- Each color component may be considered to have a nominal range of 0 to 1, but larger values are permitted — corresponding to bright light sources and other such things which it is reasonable to “overexpose”. (No meaning is given to negative values, but they are permitted.)
- NaN is banned so that
Eq
may be implemented. (Infinities are permitted.) - Color values 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 be treated equivalently to zero and one, respectively, but are preserved rather than clipped.
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 fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Constructs a color from components. Panics if any component is NaN. No other range checks are performed.
sourcepub const fn new_nn(
r: NotNan<f32>,
g: NotNan<f32>,
b: NotNan<f32>,
a: NotNan<f32>
) -> Self
pub const fn new_nn( r: NotNan<f32>, g: NotNan<f32>, b: NotNan<f32>, a: NotNan<f32> ) -> Self
Constructs a color from components that have already been checked for not being NaN.
Note: This exists primarily to assist the rgb_const!
macro and may be renamed
or replaced in future versions.
sourcepub fn from_luminance(luminance: f32) -> Self
pub fn from_luminance(luminance: f32) -> Self
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) -> NotNan<f32>
pub const fn red(self) -> NotNan<f32>
Returns the red color component. Values are linear (gamma = 1) and not premultiplied.
sourcepub const fn green(self) -> NotNan<f32>
pub const fn green(self) -> NotNan<f32>
Returns the green color component. Values are linear (gamma = 1) and not premultiplied.
sourcepub const fn blue(self) -> NotNan<f32>
pub const fn blue(self) -> NotNan<f32>
Returns the blue color component. Values are linear (gamma = 1) and not premultiplied.
sourcepub const fn alpha(self) -> NotNan<f32>
pub const fn alpha(self) -> NotNan<f32>
Returns the alpha component.
Alpha is not premultiplied. Alpha values less than zero and greater than one are allowed and may be returned by this method, but alpha test methods will treat
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 fn to_rgb(self) -> Rgb
pub 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) -> Self
pub fn map_rgb(self, f: impl FnOnce(Rgb) -> Rgb) -> Self
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.
sourcepub const fn from_srgb8(rgba: [u8; 4]) -> Self
pub const fn from_srgb8(rgba: [u8; 4]) -> Self
Converts sRGB 8-bits-per-component color to the corresponding linear Rgba
value.
Trait Implementations§
source§impl<'a> Arbitrary<'a> for Rgba
impl<'a> Arbitrary<'a> for Rgba
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
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§impl From<Rgba> for BlockBuilder<BlockBuilderAtom, ()>
impl From<Rgba> for BlockBuilder<BlockBuilderAtom, ()>
Equivalent to Block::builder().color(color)
.
source§impl PartialEq for Rgba
impl PartialEq for 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 StructuralEq for Rgba
impl StructuralPartialEq for Rgba
Auto Trait Implementations§
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.