Commit ff58db4a authored by debuggerx01's avatar debuggerx01 Committed by Greg Spencer

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 .
parent d43b4d0a
......@@ -49,7 +49,9 @@ class HSVColor {
} else if (max == blue) {
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;
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 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 grey = new HSVColor.fromColor(const Color.fromARGB(0xFF, 0x80, 0x80, 0x80));
expect(black.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 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(blue.toColor(), equals(const Color.fromARGB(0xFF, 0x00, 0x00, 0xFF)));
expect(grey.toColor(), equals(const Color.fromARGB(0xFF, 0x80, 0x80, 0x80)));
});
test('ColorSwatch test', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment