-
Notifications
You must be signed in to change notification settings - Fork 756
Description
In https://drafts.csswg.org/css-color-4/#hue-syntax it's stated that:
For colors very close to the neutral axis, the hue angle becomes indeterminate (for example, in Lab, minute changes in near-zero a and b values give huge changes in LCH hue angle). Therefore, sometimes a hue angle of NaN (not a number) may be returned.
Then this is later referenced in interpolation:
If one of the angles has the value NaN, then for interpolation, NaN is replaced by the value of the other hue angle. If both angles have the value NaN, then for interpolation, NaN is replaced by the value 0 for both angles.
The intent of this spec text is good and correct; it means interpolating from gray to green in LCH just becomes greener, rather than the hue swinging from red to green or something.
However, the exact mechanics of this aren't workable. NaN is limited to existing within the bounds of a calculation; it gets censored to infinity if it would escape (and infinity then gets clamped to the actual largest value the impl supports). So we can't have a NaN value just hanging out in normal CSS values. I think instead this should be phrased as achromatic colors having a "missing" hue, and then interpolation can key off of whether the hue is "missing".
Even if NaN did persist into normal CSS values, I don't think we actually want to merge "calculation for the angle yields NaN" with "achromatic color interpolates with chromatic color"; the latter is a common non-error case with an obvious solution, while the former is explicitly the result of a bad or nonsensical calculation with no obvious answer. So we really shouldn't be keying off of NaN anyway; a "real" NaN should be treated the same as an infinity (which it luckily censors itself into already), where it's an error case that just has an arbitrary answer (per #6105, effectively 0deg).