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.
This commit is contained in:
seb-hub 2021-07-23 14:59:30 +02:00 committed by GitHub
parent 17575f73ce
commit 7d28a6eb90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -125,13 +125,14 @@ def _v(m1, m2, hue):
def rgb_to_hsv(r, g, b): def rgb_to_hsv(r, g, b):
maxc = max(r, g, b) maxc = max(r, g, b)
minc = min(r, g, b) minc = min(r, g, b)
rangec = (maxc-minc)
v = maxc v = maxc
if minc == maxc: if minc == maxc:
return 0.0, 0.0, v return 0.0, 0.0, v
s = (maxc-minc) / maxc s = rangec / maxc
rc = (maxc-r) / (maxc-minc) rc = (maxc-r) / rangec
gc = (maxc-g) / (maxc-minc) gc = (maxc-g) / rangec
bc = (maxc-b) / (maxc-minc) bc = (maxc-b) / rangec
if r == maxc: if r == maxc:
h = bc-gc h = bc-gc
elif g == maxc: elif g == maxc: