Skip to main content

Rgb

Struct Rgb 

Source
pub struct Rgb {
    pub r: f32,
    pub g: f32,
    pub b: f32,
}
Expand description

A linear-light RGB color with f32 components. 一个使用 f32 分量的线性光 RGB 颜色。

Components are conventionally in [0, 1] but are not clamped by default; lighting math may produce values outside the range, and conversion to ColorRgba8 clamps them. 分量通常位于 [0, 1] 内,但默认不会截断;光照运算可能产生超出该范围的值,转换为 ColorRgba8 时会进行截断。

Fields§

§r: f32

Red component. 红色分量。

§g: f32

Green component. 绿色分量。

§b: f32

Blue component. 蓝色分量。

Implementations§

Source§

impl Rgb

Source

pub const BLACK: Self

Pure black. 纯黑。

Source

pub const WHITE: Self

Pure white. 纯白。

Source

pub const fn new(r: f32, g: f32, b: f32) -> Self

Construct a color from three components. 用三个分量构造一个颜色。

Source

pub fn to_rgba8(self) -> ColorRgba8

Quantize to 8-bit RGBA, truncating toward zero. 量化到 8 位 RGBA,向零截断。

The as u8 cast saturates: values below 0 clamp to 0, values above 1 clamp to 255, and NaN clamps to 0. as u8 转换是饱和的:小于 0 的值截断为 0,大于 1 的值截断为 255,NaN 截断为 0。 Truncation rather than rounding is deliberate: it keeps the mapping from [0, 1] onto 0..=255 monotonic and idempotent, so quantizing an already quantized colour changes nothing. 采用截断而非四舍五入是刻意的:它使 [0, 1] 到 0..=255 的映射保持单调且幂等, 因此对已量化的颜色再次量化不会改变任何东西。

Trait Implementations§

Source§

impl Add for Rgb

Source§

type Output = Rgb

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Rgb

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Rgb

Source§

impl Debug for Rgb

Source§

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

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

impl Default for Rgb

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Mul for Rgb

Component-wise multiplication. 逐分量相乘。

Source§

type Output = Rgb

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl Mul<f32> for Rgb

Source§

type Output = Rgb

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl PartialEq for Rgb

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rgb

Source§

impl Sub for Rgb

Source§

type Output = Rgb

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more

Auto Trait Implementations§

§

impl Freeze for Rgb

§

impl RefUnwindSafe for Rgb

§

impl Send for Rgb

§

impl Sync for Rgb

§

impl Unpin for Rgb

§

impl UnsafeUnpin 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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.