Fix HSL to RGB conversion when hue < 60 #22
Merged
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.
Problem
When converting from HSL to RGB, the RGB values do not always come out as expected. This is only an issue when the original color's hue value is less than 60, which, when divided by
60.0in theremainderfunction, results in a value less than 1 but greater than or equal to 0.In the example below, converting the color to RGB changes it from yellow to red:
The following example uses the same color, but the hue has been shifted to
60, making the value ofh / 60.0a whole number and resulting in the correct conversion:Solution
Leverage Erlang's
:math.fmodfunction in theremainderfunction to properly handle cases where dividing the hue by60.0results in a non-whole number.Using the examples above, we can see the comparison of running the remainder function before and after this change: