summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorseb-hub <45536464+seb-hub@users.noreply.github.com>2021-07-23 12:59:30 (GMT)
committerGitHub <noreply@github.com>2021-07-23 12:59:30 (GMT)
commit7d28a6eb90e2e381e13ba21073c6868fdf6eb058 (patch)
treea08f8f6b02759d3330bbf6c3c5014570cc4b5a7a
parent17575f73ce2cb9f3a4eb4cc416c690f9a4e7205c (diff)
downloadcpython-7d28a6eb90e2e381e13ba21073c6868fdf6eb058.zip
cpython-7d28a6eb90e2e381e13ba21073c6868fdf6eb058.tar.gz
cpython-7d28a6eb90e2e381e13ba21073c6868fdf6eb058.tar.bz2
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.
-rw-r--r--Lib/colorsys.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/colorsys.py b/Lib/colorsys.py
index 0f52512..9bdc83e 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: