From a7eb78d249b440be1091419fb3de6aa387fb8e88 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Mon, 17 Aug 2020 02:21:21 -0400 Subject: [PATCH] fix bug in generating complement for colors with hue under 180deg --- src/color/mod.rs | 8 ++------ tests/color.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/color/mod.rs b/src/color/mod.rs index 38db906..e8eb1dc 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -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) } } diff --git a/tests/color.rs b/tests/color.rs index 66f5057..91832d2 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -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",