w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.46k stars 658 forks source link

[css-color-4] rgb-to-hsl source code produced hue NaN when rgb values are equal #8304

Closed shuai-z closed 1 year ago

shuai-z commented 1 year ago

The souce code in Converting sRGB Colors to HSL (or file css-color-4/rgbToHsl.js) produced hue as NaN when max equals to min. it should be 0 in this case.

svgeesus commented 1 year ago

Yes, this is as expected. The hue is powerless, which is represented in CSS with the keyword none and in code with the value NaN.

For example, in hsl(), the hue component is powerless when the saturation component is 0%; a 0% saturation indicates a grayscale color, which has no hue at all, so 0deg and 180deg, or any other angle, will give the exact same result.

If such a color value is converted to another color space, the value 0 will be used for the missing value. However, if two colors are interpolated and one has a missing value while the other has a valid value for an analogous component, then the missing value is taken from that second color.