Skip to content

Commit 7d28a6e

Browse files
authored
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.
1 parent 17575f7 commit 7d28a6e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/colorsys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ def _v(m1, m2, hue):
125125
def rgb_to_hsv(r, g, b):
126126
maxc = max(r, g, b)
127127
minc = min(r, g, b)
128+
rangec = (maxc-minc)
128129
v = maxc
129130
if minc == maxc:
130131
return 0.0, 0.0, v
131-
s = (maxc-minc) / maxc
132-
rc = (maxc-r) / (maxc-minc)
133-
gc = (maxc-g) / (maxc-minc)
134-
bc = (maxc-b) / (maxc-minc)
132+
s = rangec / maxc
133+
rc = (maxc-r) / rangec
134+
gc = (maxc-g) / rangec
135+
bc = (maxc-b) / rangec
135136
if r == maxc:
136137
h = bc-gc
137138
elif g == maxc:

0 commit comments

Comments
 (0)