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
impl Rgb
sourcepub const ONE: Rgb = _
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”.
sourcepub fn new(r: f32, g: f32, b: f32) -> Self
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.
sourcepub const fn new_nn(r: NotNan<f32>, g: NotNan<f32>, b: NotNan<f32>) -> Self
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.
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 with_alpha(self, alpha: NotNan<f32>) -> Rgba
pub const fn with_alpha(self, alpha: NotNan<f32>) -> Rgba
Adds an alpha component to produce an Rgba color.
sourcepub const fn with_alpha_one(self) -> Rgba
pub const fn with_alpha_one(self) -> Rgba
Adds an alpha component of 1.0
(fully opaque) to produce an Rgba color.
sourcepub const fn red(self) -> NotNan<f32>
pub const fn red(self) -> NotNan<f32>
Returns the red color component. Values are linear (gamma = 1).
sourcepub const fn green(self) -> NotNan<f32>
pub const fn green(self) -> NotNan<f32>
Returns the green color component. Values are linear (gamma = 1).
sourcepub const fn blue(self) -> NotNan<f32>
pub const fn blue(self) -> NotNan<f32>
Returns the blue color component. Values are linear (gamma = 1).
sourcepub fn luminance(self) -> f32
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());
sourcepub const fn from_srgb8(rgb: [u8; 3]) -> Self
pub const fn from_srgb8(rgb: [u8; 3]) -> Self
Converts sRGB 8-bits-per-component color to the corresponding linear Rgba
value.
Trait Implementations§
source§impl AddAssign for Rgb
impl AddAssign for Rgb
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moresource§impl<'a> Arbitrary<'a> for Rgb
impl<'a> Arbitrary<'a> for Rgb
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<Rgb> for BlockBuilder<BlockBuilderAtom, ()>
impl From<Rgb> for BlockBuilder<BlockBuilderAtom, ()>
Equivalent to Block::builder().color(color.with_alpha_one())
.
source§impl From<Rgb> for PackedLight
impl From<Rgb> for PackedLight
source§impl From<Rgb888> for Rgb
impl From<Rgb888> for Rgb
Adapt embedded_graphics
’s most general color type to ours.
source§impl Sum for Rgb
impl Sum for Rgb
There is no corresponding impl Sum for Rgba
because the alpha would
not have a universally reasonable interpretation.
source§impl<'a> VoxelColor<'a> for Rgb
impl<'a> VoxelColor<'a> for Rgb
source§fn into_blocks(self) -> VoxelBrush<'a>
fn into_blocks(self) -> VoxelBrush<'a>
VoxelBrush
, the most general form of blocky drawing.impl Copy for Rgb
impl Eq for Rgb
impl StructuralEq for Rgb
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> 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.