Skip to content

Commit

Permalink
fix(hslToRgb): correct % for potential negative hue
Browse files Browse the repository at this point in the history
Due to the Javascript modulo bug
(https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers),
any negative value for hue results in a bug where the resulting color will be black. Negative hues
should cycle through to 359, so that functions like `adjustHue()` can provide consistent behavior
for all colors.

fix #437
  • Loading branch information
davidde authored and bhough committed May 18, 2019
1 parent faac33f commit 5c306c8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/internalHelpers/_hslToRgb.js
Expand Up @@ -22,9 +22,9 @@ function hslToRgb(
}

// formular from https://en.wikipedia.org/wiki/HSL_and_HSV
const huePrime = hue % 360 / 60
const huePrime = (((hue % 360) + 360) % 360) / 60 // Corrected for potential negative hue
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation
const secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1))
const secondComponent = chroma * (1 - Math.abs((huePrime % 2) - 1))

let red = 0
let green = 0
Expand Down

0 comments on commit 5c306c8

Please sign in to comment.