Handle negative hues
This commit is contained in:
parent
a328617001
commit
4303bd451c
@ -246,7 +246,11 @@ impl Color {
|
|||||||
|
|
||||||
/// Create RGBA representation from HSLA values
|
/// Create RGBA representation from HSLA values
|
||||||
pub fn from_hsla(hue: Number, saturation: Number, luminance: Number, alpha: Number) -> Self {
|
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 saturation = clamp!(saturation, 0, 1);
|
||||||
let luminance = clamp!(luminance, 0, 1);
|
let luminance = clamp!(luminance, 0, 1);
|
||||||
let alpha = clamp!(alpha, 0, 1);
|
let alpha = clamp!(alpha, 0, 1);
|
||||||
|
@ -128,6 +128,11 @@ test!(
|
|||||||
"a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n",
|
"a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n",
|
||||||
"a {\n color: #fbfdfe;\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!(
|
test!(
|
||||||
hsla_named,
|
hsla_named,
|
||||||
"a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",
|
"a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user