Fix hue algorithm when red == blue and red > green

This commit is contained in:
ConnorSkees 2020-02-14 09:46:50 -05:00
parent 65c5c209f3
commit 38802b69c5
2 changed files with 9 additions and 4 deletions

View File

@ -102,7 +102,7 @@ impl Color {
(((min + max) / Number::from(2)) * Number::from(100)).round()
}
pub fn as_hsla(&self) -> (Number, Number, Number, Number) {
fn as_hsla(&self) -> (Number, Number, Number, Number) {
let red = self.red.clone() / Number::from(255);
let green = self.green.clone() / Number::from(255);
let blue = self.blue.clone() / Number::from(255);
@ -125,12 +125,12 @@ impl Color {
let mut hue = if min == max {
Number::from(0)
} else if red == max {
(green - blue) / (max - min)
} else if blue == max {
Number::from(4) + (red - green) / (max - min)
} else if green == max {
Number::from(2) + (blue - red) / (max - min)
} else {
Number::from(4) + (red - green) / (max - min)
(green - blue) / (max - min)
};
if hue < Number::from(0) {

View File

@ -304,3 +304,8 @@ test!(
"a {\n color: desaturate(#855, 20%);\n}\n",
"a {\n color: #726b6b;\n}\n"
);
test!(
desaturate_correctly_calculates_hue,
"a {\n color: desaturate(plum, 14%);\n}\n",
"a {\n color: #d4a9d4;\n}\n"
);