From 4365b75629fb9ef3d00a55f92001f60b178cb389 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 10 Apr 2020 13:48:31 -0700 Subject: [PATCH] Treat negative hues correctly in HSL. --- color/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/color/src/lib.rs b/color/src/lib.rs index 7b45e91d..8bafd8f7 100644 --- a/color/src/lib.rs +++ b/color/src/lib.rs @@ -113,7 +113,12 @@ impl ColorF { pub fn from_hsla(mut h: f32, s: f32, l: f32, a: f32) -> ColorF { // https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB + // Make sure hue is always positive. h %= 2.0 * PI; + if h < 0.0 { + h += 2.0 * PI; + } + h *= 3.0 / PI; // Calculate chroma.