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: f32Red component. 红色分量。
g: f32Green component. 绿色分量。
b: f32Blue component. 蓝色分量。
Implementations§
Source§impl Rgb
impl Rgb
Sourcepub const fn new(r: f32, g: f32, b: f32) -> Self
pub const fn new(r: f32, g: f32, b: f32) -> Self
Construct a color from three components. 用三个分量构造一个颜色。
Sourcepub fn to_rgba8(self) -> ColorRgba8
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 的映射保持单调且幂等,
因此对已量化的颜色再次量化不会改变任何东西。