Fix hue algorithm when red == blue and red > green
This commit is contained in:
parent
65c5c209f3
commit
38802b69c5
@ -102,7 +102,7 @@ impl Color {
|
|||||||
(((min + max) / Number::from(2)) * Number::from(100)).round()
|
(((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 red = self.red.clone() / Number::from(255);
|
||||||
let green = self.green.clone() / Number::from(255);
|
let green = self.green.clone() / Number::from(255);
|
||||||
let blue = self.blue.clone() / Number::from(255);
|
let blue = self.blue.clone() / Number::from(255);
|
||||||
@ -125,12 +125,12 @@ impl Color {
|
|||||||
|
|
||||||
let mut hue = if min == max {
|
let mut hue = if min == max {
|
||||||
Number::from(0)
|
Number::from(0)
|
||||||
} else if red == max {
|
} else if blue == max {
|
||||||
(green - blue) / (max - min)
|
Number::from(4) + (red - green) / (max - min)
|
||||||
} else if green == max {
|
} else if green == max {
|
||||||
Number::from(2) + (blue - red) / (max - min)
|
Number::from(2) + (blue - red) / (max - min)
|
||||||
} else {
|
} else {
|
||||||
Number::from(4) + (red - green) / (max - min)
|
(green - blue) / (max - min)
|
||||||
};
|
};
|
||||||
|
|
||||||
if hue < Number::from(0) {
|
if hue < Number::from(0) {
|
||||||
|
@ -304,3 +304,8 @@ test!(
|
|||||||
"a {\n color: desaturate(#855, 20%);\n}\n",
|
"a {\n color: desaturate(#855, 20%);\n}\n",
|
||||||
"a {\n color: #726b6b;\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"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user