Fix hue to 0.0 when red == green == blue. (#16872)
When passing a Color object with same R/G/B code ( e.g. [new Color.fromRGBO(100, 100, 100, 1.0)] ) to HSVColor.fromColor(Color color) , the hue in return will be NaN .
This commit is contained in:
parent
d43b4d0ad8
commit
ff58db4ac3
@ -50,6 +50,8 @@ class HSVColor {
|
|||||||
hue = 60.0 * (((red - green) / delta) + 4);
|
hue = 60.0 * (((red - green) / delta) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// fix hue to 0.0 when red == green == blue.
|
||||||
|
hue = hue.isNaN ? 0.0 : hue;
|
||||||
final double saturation = max == 0.0 ? 0.0 : delta / max;
|
final double saturation = max == 0.0 ? 0.0 : delta / max;
|
||||||
|
|
||||||
return new HSVColor.fromAHSV(alpha, hue, saturation, max);
|
return new HSVColor.fromAHSV(alpha, hue, saturation, max);
|
||||||
|
@ -32,11 +32,13 @@ void main() {
|
|||||||
final HSVColor red = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0xFF, 0x00, 0x00));
|
final HSVColor red = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0xFF, 0x00, 0x00));
|
||||||
final HSVColor green = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0x00, 0xFF, 0x00));
|
final HSVColor green = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0x00, 0xFF, 0x00));
|
||||||
final HSVColor blue = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0x00, 0x00, 0xFF));
|
final HSVColor blue = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0x00, 0x00, 0xFF));
|
||||||
|
final HSVColor grey = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0x80, 0x80, 0x80));
|
||||||
|
|
||||||
expect(black.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0x00, 0x00)));
|
expect(black.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0x00, 0x00)));
|
||||||
expect(red.toColor(), equals(const Color.fromARGB(0xFF, 0xFF, 0x00, 0x00)));
|
expect(red.toColor(), equals(const Color.fromARGB(0xFF, 0xFF, 0x00, 0x00)));
|
||||||
expect(green.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0xFF, 0x00)));
|
expect(green.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0xFF, 0x00)));
|
||||||
expect(blue.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0x00, 0xFF)));
|
expect(blue.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0x00, 0xFF)));
|
||||||
|
expect(grey.toColor(), equals(const Color.fromARGB(0xFF, 0x80, 0x80, 0x80)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ColorSwatch test', () {
|
test('ColorSwatch test', () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user