Handle negative hues

This commit is contained in:
ConnorSkees 2020-02-14 17:52:25 -05:00
parent a328617001
commit 4303bd451c
2 changed files with 10 additions and 1 deletions

View File

@ -246,7 +246,11 @@ impl Color {
/// Create RGBA representation from HSLA values
pub fn from_hsla(hue: Number, saturation: Number, luminance: Number, alpha: Number) -> Self {
let mut hue = clamp!(hue, 0, 360);
let mut hue = if hue < Number::from(0) {
Number::from(360) + clamp!(hue, -360, 360)
} else {
clamp!(hue, -360, 360)
};
let saturation = clamp!(saturation, 0, 1);
let luminance = clamp!(luminance, 0, 1);
let alpha = clamp!(alpha, 0, 1);

View File

@ -128,6 +128,11 @@ test!(
"a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n",
"a {\n color: #fbfdfe;\n}\n"
);
test!(
hsl_negative_hue,
"a {\n color: hsl(-60deg, 100%, 50%);\n}\n",
"a {\n color: fuchsia;\n}\n"
);
test!(
hsla_named,
"a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",