Struct all_is_cubes::math::Rgb

source ·
pub struct Rgb(/* private fields */);
Expand description

A floating-point RGB color value.

  • Each 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).

Implementations§

source§

impl Rgb

source

pub const ZERO: Rgb = _

Black; the constant equal to Rgb::new(0., 0., 0.).unwrap().

source

pub const ONE: Rgb = _

Nominal white; the constant equal to Rgb::new(1., 1., 1.).unwrap().

Note that brighter values may exist; the color system “supports HDR”.

source

pub fn new(r: f32, g: f32, b: 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>) -> 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 with_alpha(self, alpha: NotNan<f32>) -> Rgba

Adds an alpha component to produce an Rgba color.

source

pub const fn with_alpha_one(self) -> Rgba

Adds an alpha component of 1.0 (fully opaque) to produce an Rgba color.

source

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

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

source

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

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

source

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

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

source

pub fn luminance(self) -> f32

Combines the red, green, and blue components to obtain a relative luminance (“grayscale”) value. This will be equal to 1 if all components are 1.

use all_is_cubes::math::Rgb;

assert_eq!(0.0, Rgb::ZERO.luminance());
assert_eq!(0.5, (Rgb::ONE * 0.5).luminance());
assert_eq!(1.0, Rgb::ONE.luminance());
assert_eq!(2.0, (Rgb::ONE * 2.0).luminance());

assert_eq!(0.2126, Rgb::new(1., 0., 0.).luminance());
assert_eq!(0.7152, Rgb::new(0., 1., 0.).luminance());
assert_eq!(0.0722, Rgb::new(0., 0., 1.).luminance());
source

pub const fn from_srgb8(rgb: [u8; 3]) -> 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 Add for Rgb

§

type Output = Rgb

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl AddAssign for Rgb

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<'a> Arbitrary<'a> for Rgb

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 Rgb

source§

fn clone(&self) -> Rgb

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 Rgb

source§

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

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

impl From<[NotNan<f32>; 3]> for Rgb

source§

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

Converts to this type from the input type.
source§

impl From<Rgb> for [NotNan<f32>; 3]

source§

fn from(value: Rgb) -> Self

Converts to this type from the input type.
source§

impl From<Rgb> for [f32; 3]

source§

fn from(value: Rgb) -> Self

Converts to this type from the input type.
source§

impl From<Rgb> for Atom

source§

fn from(color: Rgb) -> Self

Convert a color to an Atom with default attributes.

source§

impl From<Rgb> for Block

source§

fn from(color: Rgb) -> Self

Convert a color to a block with default attributes.

source§

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

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

source§

fn from(color: Rgb) -> Self

Converts to this type from the input type.
source§

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

source§

fn from(color: Rgb) -> Self

Convert a color to a block with default attributes.

source§

impl From<Rgb> for PackedLight

source§

fn from(value: Rgb) -> Self

Converts to this type from the input type.
source§

impl From<Rgb> for Vector3D<f32, Intensity>

source§

fn from(value: Rgb) -> Self

Converts to this type from the input type.
source§

impl From<Rgb888> for Rgb

Adapt embedded_graphics’s most general color type to ours.

source§

fn from(color: Rgb888) -> Rgb

Converts to this type from the input type.
source§

impl From<Vector3D<NotNan<f32>, Intensity>> for Rgb

source§

fn from(value: Vector3D<NotNan<f32>, Intensity>) -> Self

Converts to this type from the input type.
source§

impl Hash for Rgb

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 Mul<NotNan<f32>> for Rgb

Multiplies this color value by a scalar.

source§

fn mul(self, scalar: NotNan<f32>) -> Self

Multiplies this color value by a scalar.

§

type Output = Rgb

The resulting type after applying the * operator.
source§

impl Mul<f32> for Rgb

Multiplies this color value by a scalar. Panics if the scalar is NaN.

source§

fn mul(self, scalar: f32) -> Self

Multiplies this color value by a scalar. Panics if the scalar is NaN.

§

type Output = Rgb

The resulting type after applying the * operator.
source§

impl Mul for Rgb

Multiplies two color values componentwise.

source§

fn mul(self, other: Rgb) -> Self

Multiplies two color values componentwise.

§

type Output = Rgb

The resulting type after applying the * operator.
source§

impl PartialEq for Rgb

source§

fn eq(&self, other: &Rgb) -> 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 Rgb

§

type Raw = ()

Raw data type. Read more
source§

impl Sub for Rgb

§

type Output = Rgb

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl Sum for Rgb

There is no corresponding impl Sum for Rgba because the alpha would not have a universally reasonable interpretation.

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl TryFrom<Vector3D<f32, Intensity>> for Rgb

§

type Error = FloatIsNan

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

fn try_from(value: Vector3D<f32, Intensity>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> VoxelColor<'a> for Rgb

source§

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

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

impl Copy for Rgb

source§

impl Eq for Rgb

source§

impl StructuralEq for Rgb

source§

impl StructuralPartialEq for Rgb

Auto Trait Implementations§

§

impl RefUnwindSafe for Rgb

§

impl Send for Rgb

§

impl Sync for Rgb

§

impl Unpin for Rgb

§

impl UnwindSafe for Rgb

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.