From 7d28a6eb90e2e381e13ba21073c6868fdf6eb058 Mon Sep 17 00:00:00 2001 From: seb-hub <45536464+seb-hub@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:59:30 +0200 Subject: [PATCH] Improve consistency of colorsys.rgb_to_hsv (GH-27277) Cache repeated difference to make code easier to read and consistent with colorsys.rgb_to_hls. --- Lib/colorsys.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/colorsys.py b/Lib/colorsys.py index 0f52512a67d..9bdc83e3772 100644 --- a/Lib/colorsys.py +++ b/Lib/colorsys.py @@ -125,13 +125,14 @@ def _v(m1, m2, hue): def rgb_to_hsv(r, g, b): maxc = max(r, g, b) minc = min(r, g, b) + rangec = (maxc-minc) v = maxc if minc == maxc: return 0.0, 0.0, v - s = (maxc-minc) / maxc - rc = (maxc-r) / (maxc-minc) - gc = (maxc-g) / (maxc-minc) - bc = (maxc-b) / (maxc-minc) + s = rangec / maxc + rc = (maxc-r) / rangec + gc = (maxc-g) / rangec + bc = (maxc-b) / rangec if r == maxc: h = bc-gc elif g == maxc: