[csswg-drafts] [css-color-4] Conversion precision for hue in LCH model creates false results (#5309)

snigo has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-color-4] Conversion precision for hue in LCH model creates false results ==
One thing I have noticed with sRGB to Lab/LCH conversion as it produces chaotic and very incorrect hue value in LCH color model. Converting any shade of gray to Lab/LCH will result in components `a` and `b` very close to zero, but still **not zero**. It is absolutely fine for calculating chroma, as square root of those numbers will still result in number very close to zero, however calculating hue with `Math.atan()` gives very high range of (falsy) values whenever there is any difference between `a` and `b`, which always there!

```js
Math.atan2(0.0000000005, -0.0000000001) * 180 / Math.PI; // 101.30993247402021
Math.atan2(0.0000000005, 0.0000000001) * 180 / Math.PI; // 78.69006752597979
Math.atan2(0.0000000005, 0.0000000003) * 180 / Math.PI; // 59.03624346792648
```

Rounding to 3 decimal places of `a` and `b` solves problem for any shade of gray resulting in correct value of `0`, however creates incorrect results for some highly desaturated colors like `hsl(0 1% 1%)` or `hsl(0 1% 99%)`, which in my opinion is better comparing to incorrect results for any shade of gray (including white and black)


Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5309 using your GitHub account

Received on Thursday, 9 July 2020 15:14:41 UTC