Properly handle hue values above and below maximum
This commit is contained in:
parent
4303bd451c
commit
ae9b97a6b2
@ -246,10 +246,14 @@ impl Color {
|
||||
|
||||
/// Create RGBA representation from HSLA values
|
||||
pub fn from_hsla(hue: Number, saturation: Number, luminance: Number, alpha: Number) -> Self {
|
||||
let mut hue = if hue < Number::from(0) {
|
||||
let mut hue = if hue > Number::from(360) {
|
||||
hue % Number::from(360)
|
||||
} else if hue < Number::from(-360) {
|
||||
Number::from(360) + hue % Number::from(360)
|
||||
} else if hue < Number::from(0) {
|
||||
Number::from(360) + clamp!(hue, -360, 360)
|
||||
} else {
|
||||
clamp!(hue, -360, 360)
|
||||
hue
|
||||
};
|
||||
let saturation = clamp!(saturation, 0, 1);
|
||||
let luminance = clamp!(luminance, 0, 1);
|
||||
|
@ -133,6 +133,16 @@ test!(
|
||||
"a {\n color: hsl(-60deg, 100%, 50%);\n}\n",
|
||||
"a {\n color: fuchsia;\n}\n"
|
||||
);
|
||||
test!(
|
||||
hsl_hue_above_max,
|
||||
"a {\n color: hsl(540, 100%, 50%);\n}\n",
|
||||
"a {\n color: aqua;\n}\n"
|
||||
);
|
||||
test!(
|
||||
hsl_hue_below_min,
|
||||
"a {\n color: hsl(-540, 100%, 50%);\n}\n",
|
||||
"a {\n color: aqua;\n}\n"
|
||||
);
|
||||
test!(
|
||||
hsla_named,
|
||||
"a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user