Treat negative hues correctly in HSL.

This commit is contained in:
Patrick Walton 2020-04-10 13:48:31 -07:00
parent e598249186
commit 4365b75629
1 changed files with 5 additions and 0 deletions

View File

@ -113,7 +113,12 @@ impl ColorF {
pub fn from_hsla(mut h: f32, s: f32, l: f32, a: f32) -> 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 // https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB
// Make sure hue is always positive.
h %= 2.0 * PI; h %= 2.0 * PI;
if h < 0.0 {
h += 2.0 * PI;
}
h *= 3.0 / PI; h *= 3.0 / PI;
// Calculate chroma. // Calculate chroma.