pub struct Color {
pub l: f64,
pub c: f64,
pub h: f64,
}Expand description
A color stored in OKLCH. All engine math happens in this space.
l(lightness) in0.0..=1.0. 0 is black, 1 is white.c(chroma) in0.0..~0.4. 0 is achromatic; ~0.37 is a vivid sRGB-gamut red. Values above the gamut clip on emission.h(hue) in degrees0.0..360.0. Undefined when chroma is 0, but we always store a value (typically 0) forCopy/PartialEq.
Fields§
§l: f64Lightness in 0.0..=1.0. 0 is black, 1 is white. Perceptually
uniform — equal steps in l look equally bright to the eye.
c: f64Chroma in 0.0..~0.4. 0 is achromatic; ~0.37 is a vivid
sRGB-gamut red. Values above the gamut clip on emission.
h: f64Hue in degrees 0.0..360.0. Undefined when c is 0 but
always stored (typically 0) so the struct remains Copy and
PartialEq.
Implementations§
Source§impl Color
impl Color
Sourcepub fn from_oklch(l: f64, c: f64, h: f64) -> Self
pub fn from_oklch(l: f64, c: f64, h: f64) -> Self
Construct directly from OKLCH components. Used by tests and by pipeline stages that compute coordinates rather than parse strings.
Sourcepub fn from_hex(hex: &str) -> Result<Self, ColorError>
pub fn from_hex(hex: &str) -> Result<Self, ColorError>
Parse #rrggbb or #rgb. Never panics on bad input.
Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Emit a #rrggbb string. Converts to sRGB and clamps each
channel into 0..=1 before quantizing — out-of-gamut OKLCH
coordinates are projected by channel clamping, not by hue shift.
Sourcepub fn mix(&self, other: &Color, amount: f64) -> Color
pub fn mix(&self, other: &Color, amount: f64) -> Color
Mix toward other by amount (0.0 = self, 1.0 = other).
Interpolation happens in OKLab — L, a, b each interpolate
linearly — so the result tracks perceived color without the
hue-wraparound traps of LCh-space mixing. This is the engine’s
port of CSS color-mix() for the cases this engine needs.