Struct Oklch

Stores a color as Oklab lightness, chroma, and hue.

struct Oklch(T)
  
if (is(T == float) || is(T == double));

Use OKLCH when editing or interpolating perceptual lightness, colorfulness, or hue directly. Lightness and chroma are raw mathematical values; chroma is not silently clamped or canonicalized, and hue preserves its raw degree value.

T must be float or double. The natural .init value contains NaNs and is not a usable color.

Fields

NameTypeDescription
c TChroma component.
h OklabHue!TRaw, degree-based Oklab-family hue.
l TPerceptual lightness component.

Properties

NameTypeDescription
canonicalized[get] OklchReturns an equivalent representation with non-negative chroma.
isAchromatic[get] boolReports whether chroma is exactly zero.

Methods

NameDescription
isNearAchromatic (epsilon) Tests chroma against a caller-selected near-achromatic threshold.

Aliases

NameDescription
Scalar Scalar component type.

Example

const color = Oklchd(
    0.55,
    0.12,
    OklabHued.fromDegrees(250.0)
);

assert(color.l == 0.55);
assert(color.c == 0.12);
assert(color.h.rawDegrees == 250.0);