From 5c306c86ef92df1dd40cbf7695b5b1f85579e872 Mon Sep 17 00:00:00 2001 From: DavidDeprost Date: Sun, 12 May 2019 22:49:34 +0200 Subject: [PATCH] fix(hslToRgb): correct % for potential negative hue 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 --- src/internalHelpers/_hslToRgb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internalHelpers/_hslToRgb.js b/src/internalHelpers/_hslToRgb.js index 0a07ffa5..b2732b7e 100644 --- a/src/internalHelpers/_hslToRgb.js +++ b/src/internalHelpers/_hslToRgb.js @@ -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