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

source

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.

source

pub const BLACK: Rgba = _

Black; identical to Rgba::new(0.0, 0.0, 0.0, 1.0) except for being a constant.

source

pub const WHITE: Rgba = _

White; identical to Rgba::new(1.0, 1.0, 1.0, 1.0) except for being a constant.

source

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.

source

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.

source

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.

source

pub const fn red(self) -> NotNan<f32>

Returns the red color component. Values are linear (gamma = 1) and not premultiplied.

source

pub const fn green(self) -> NotNan<f32>

Returns the green color component. Values are linear (gamma = 1) and not premultiplied.

source

pub const fn blue(self) -> NotNan<f32>

Returns the blue color component. Values are linear (gamma = 1) and not premultiplied.

source

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

source

pub fn fully_transparent(self) -> bool

Returns whether this color is fully transparent, or has an alpha component of zero or less.

source

pub fn fully_opaque(self) -> bool

Returns whether this color is fully opaque, or has an alpha component of one or greater.

source

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.

source

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.

source

pub fn map_rgb(self, f: impl FnOnce(Rgb) -> Rgb) -> Self

Applies a function to the RGB portion of this color.

source

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.

source

pub fn to_srgb8(self) -> [u8; 4]

Converts this color lossily to sRGB 8-bits-per-component color.

source

pub const fn from_srgb8(rgba: [u8; 4]) -> Self

Converts sRGB 8-bits-per-component color to the corresponding linear Rgba value.

source

pub fn clamp(self) -> Self

Clamp each component to lie within the range 0 to 1, inclusive.

Trait Implementations§

source§

impl<'a> Arbitrary<'a> for Rgba

source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

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 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 Clone for Rgba

source§

fn clone(&self) -> Rgba

Returns a copy 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 Debug for Rgba

source§

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

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

impl From<[NotNan<f32>; 4]> for Rgba

source§

fn from(value: [NotNan<f32>; 4]) -> Self

Converts to this type from the input type.
source§

impl From<ColorBuf> for Rgba

source§

fn from(buf: ColorBuf) -> Rgba

Returns the color (image pixel) accumulated in this buffer.

Not tone mapped; consider using Camera::post_process_color() for that.

source§

impl From<Rgba> for [NotNan<f32>; 4]

source§

fn from(value: Rgba) -> Self

Converts to this type from the input type.
source§

impl From<Rgba> for [f32; 4]

source§

fn from(value: Rgba) -> Self

Converts to this type from the input type.
source§

impl From<Rgba> for Atom

source§

fn from(color: Rgba) -> Self

Convert a color to an Atom with default attributes.

source§

impl From<Rgba> for Block

source§

fn from(color: Rgba) -> Self

Convert a color to a block with default attributes.

source§

impl From<Rgba> for BlockBuilder<BlockBuilderAtom, ()>

Equivalent to Block::builder().color(color).

source§

fn from(color: Rgba) -> Self

Converts to this type from the input type.
source§

impl From<Rgba> for Cow<'_, Block>

source§

fn from(color: Rgba) -> Self

Convert a color to a block with default attributes.

source§

impl Hash for Rgba

source§

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

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 PartialEq for Rgba

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PixelColor for Rgba

§

type Raw = ()

Raw data type. Read more
source§

impl<'a> VoxelColor<'a> for Rgba

source§

fn into_blocks(self) -> VoxelBrush<'a>

Returns a corresponding VoxelBrush, the most general form of blocky drawing.
source§

impl Copy for Rgba

source§

impl Eq for Rgba

source§

impl StructuralEq for Rgba

source§

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> 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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, 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.

§

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

§

type EqTo = 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,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.