Fix hsvColor returning a NaN hue for achromatic (grey) colors - #1454
Open
Sreekant13 wants to merge 1 commit into
Open
Fix hsvColor returning a NaN hue for achromatic (grey) colors#1454Sreekant13 wants to merge 1 commit into
Sreekant13 wants to merge 1 commit into
Conversation
hsvColor() divides by Delta (max - min) when computing the hue, but only guarded against max == 0, not Delta == 0. For any grey where r == g == b > 0, Delta is 0, so the hue became 60 * 0 / 0 = NaN (e.g. hsvColor(vec3(0.5)) gave a NaN hue instead of 0). Guard the achromatic case and set the hue to 0, consistent with the reverse rgbColor() which already special-cases achromatic colors. Add a regression test covering a grey input and its round-trip.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hsvColor()computes the hue by dividing byDelta = max - min, but it only guards againstmax == 0, notDelta == 0. For any achromatic color wherer == g == b > 0(a grey),Deltais0, so the hue becomes60 * 0 / 0 = NaN:The reverse function
rgbColor()already special-cases achromatic colors (if(hsv.y == 0)), so this makeshsvColor()consistent: whenDelta == 0the hue is undefined and set to0(saturation is already0). Colored inputs are unchanged.Added a regression test in test/gtx/gtx_color_space.cpp covering a grey input (hue must be
0, notNaN) and its round-trip.