fix bug in generating complement for colors with hue under 180deg

This commit is contained in:
Connor Skees 2020-08-17 02:21:21 -04:00
parent 790b0685cb
commit a7eb78d249
2 changed files with 12 additions and 11 deletions

View File

@ -465,12 +465,8 @@ impl Color {
pub fn complement(&self) -> Self {
let (hue, saturation, luminance, alpha) = self.as_hsla();
let hue = if hue > Number::from(180) {
Number::from(360) - hue
} else {
hue + Number::from(180)
};
Color::from_hsla(hue, saturation, luminance, alpha)
Color::from_hsla(hue + Number::from(180), saturation, luminance, alpha)
}
}

View File

@ -387,16 +387,21 @@ test!(
"a {\n color: gray;\n}\n"
);
test!(grayscale_number, "a {\n color: grayscale(15%);\n}\n");
// handle special functions better!
// test!(
// grayscale_number_casing,
// "a {\n color: grAyscaLe(15%);\n}\n"
// );
test!(
#[ignore]
grayscale_number_casing,
"a {\n color: grAyscaLe(15%);\n}\n"
);
test!(
complement,
"a {\n color: complement(red);\n}\n",
"a {\n color: aqua;\n}\n"
);
test!(
complement_hue_under_180,
"a {\n color: complement(#abcdef);\n}\n",
"a {\n color: #efcdab;\n}\n"
);
test!(
mix_no_weight,
"a {\n color: mix(#f00, #00f);\n}\n",