Closed xi closed 4 years ago
Interesting! Thank you for the feedback and the contribution.
This does not happen in RGB and Lab space, but appears in both HSL and LCh, which have angular Hue values.
If I understand it correctly, your solution would have an impact on all mix
ing results and it would not be the same interpolation between two colors. What if, instead, we just add a special case for pure black and pure white (this issue should not appear for any other colors?). In this case, we could just select the hue from the "other" color. So mix blue black
would mix "blue" with a "black" that has a hue of 240°. What do you think?
Consider this case:
$ pastel mix -s hsl 100 blue
#880088
$ pasel mix -s hsl 010 blue
#008888
These colors are practically black, so they should have a similar effect as pure black.
This might be personal taste, but I find this approach produces less unexpected results in general.
The mix
function is also used to create gradients. If a user explicitly chooses the HSL space (and a start color with a "red hue"), I think it is expected that the hue rotates from red to blue:
pastel gradient -n 20 -s hsl 100 blue | pastel format
If you don't want that rotation along the hue axis, you can always choose a different color space (RGB, if you want to be similar to HSL; Lab if you want to be similar to LCh).
That being said, I agree that the behavior of pure black
and pure white
could definitely be surprising :+1:
@xi I have pushed an update which fixes the original issue when we mix with saturation-less / gray colors. See 4305363.
Thank you very much for bringing this up.
For unsaturated colors, the hue is not as relevant. Consider mixing black and blue:
As black does not have a meaningful hue, it is assumed to be 0 (red). So the result is a dark purple instead of a dark blue.
My proposal is to weight the hues by saturation. So in the example above, the red hue of black would be ignored because it has a saturation of 0. I understad this is more complex but does ultimately lead to less unexpected results.
(I did not do anything special to prevent devision by zero. rust seems to be smart enough to handle that itself, but I am not proficient enough to know exactly how.)