From 579c24625e93b67fd74245fe835cb34906ee7090 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Tue, 14 Jul 2020 17:32:01 +0200 Subject: [PATCH] Avoid division by zero --- src/kaka/cakelight/Color.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java index 0332371..5ea98cd 100644 --- a/src/kaka/cakelight/Color.java +++ b/src/kaka/cakelight/Color.java @@ -73,12 +73,16 @@ public class Color { s = delta / max; // Hue - if (r == max) { - h = (g - b) / delta; // between yellow & magenta - } else if (g == max) { - h = 2 + (b - r) / delta; // between cyan & yellow + if (delta > 0) { + if (r == max) { + h = (g - b) / delta; // between yellow & magenta + } else if (g == max) { + h = 2 + (b - r) / delta; // between cyan & yellow + } else { + h = 4 + (r - g) / delta; // between magenta & cyan + } } else { - h = 4 + (r - g) / delta; // between magenta & cyan + h = 0; } h /= 6.0; -- 2.11.0