Skip to content

ColorUtils: Handle cases where hue is -1 in linearInterpolate

Arjen Hiemstra requested to merge work/ahiemstra/interpolation into master

When a color has a saturation of 0 the hue is undefined. QColor expresses this by returning -1 for the hue of those colors. When that happens, just naively interpolating that results in incorrect colors. So instead account for this case by either using the other color's hue or if both are -1, just using 0.

Additionally, since we're using floats in the calculations here, use the various float-based getters/setters instead of relying on implicit conversions.

The second commit removes an optimisation(?) for transparent colours that would result in incorrect colors.

The last commit adds an autotest to verify that behaviour is all correct.

Edited by Arjen Hiemstra

Merge request reports