From: seb-hub <45536464+seb-hub@users.noreply.github.com> Date: Fri, 23 Jul 2021 12:59:30 +0000 (+0200) Subject: Improve consistency of colorsys.rgb_to_hsv (GH-27277) X-Git-Tag: v3.11.0a1~601 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d28a6eb90e2e381e13ba21073c6868fdf6eb058;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Lib/colorsys.py b/Lib/colorsys.py index 0f52512a67d8..9bdc83e37726 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: