HACKER Q&A
📣 rikroots

Why are the calculations in latest WC3 CSS Color Module Level 4 wrong?


I was looking for a calculation to convert between RGB and HSL color spaces and found some equations in the latest W3C CSS Color Module Level 4 working draft (15 Dec 2021). But the calculation for converting sRGB colors to HSL colors sets the hue value to NaN [1]. Why? If I can't trust the standard to be correct, then what can I trust?

[1] - https://www.w3.org/TR/css-color-4/#rgb-to-hsl


  👤 Someone Accepted Answer ✓
> But the calculation for converting sRGB colors to HSL colors sets the hue value to NaN

Only if the value of d is zero. That happens iff r == g == b, so for white, black and the gray values in between them.

That technically is right. https://en.wikipedia.org/wiki/HSL_and_HSV:

HSL and HSV are both cylindrical geometries (fig. 2), with hue, their angular dimension, starting at the red primary at 0°, passing through the green primary at 120° and the blue primary at 240°, and then wrapping back to red at 360°. In each geometry, the central vertical axis comprises the neutral, achromatic, or gray colors ranging, from top to bottom, white at lightness 1 (value 1) to black at lightness 0 (value 0).

So, for the colors on the central axis, the hue is undefined.

Picking any specific value for the hue would be an arbitrary choice.