vaab / colour

Python color representations manipulation library (RGB, HSL, web, ...)
BSD 2-Clause "Simplified" License
319 stars 41 forks source link

the following tuple (0.9999999999999999, 0.9999999999999999, 1.0) put satuation over 1, which trigger a crash on print. #30

Closed LBdN closed 7 years ago

LBdN commented 7 years ago

r, g, b = (0.9999999999999999, 0.9999999999999999, 1.0) c = Color(red=r, green=g, blue=b) print or log c

traceback :

  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1084, in __str__
    return "%s" % self.web
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 983, in __getattr__
    return getattr(self, 'get_' + label)()
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1029, in get_web
    return hex2web(self.hex)
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 983, in __getattr__
    return getattr(self, 'get_' + label)()
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1002, in get_hex
    return rgb2hex(self.rgb)
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 983, in __getattr__
    return getattr(self, 'get_' + label)()
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 1008, in get_rgb
    return hsl2rgb(self.hsl)
  File "/home/lionel/Envs/rectitude-pyqt/local/lib/python2.7/site-packages/colour.py", line 346, in hsl2rgb
    raise ValueError("Saturation must be between 0 and 1.")
vaab commented 7 years ago

Thanks for your interest in gitchangelog. The exact issue is in:

rgb2hsl((0.9999999999999999, 1.0, 0.9999999999999994))

which produces saturation greater than 1.

The problem arise because the difference between the amount of green, red, blue is less that FLOAT_ERROR, and will then make a near division by nearly zero : expanding tremendously in one go the float approximation errors. I corrected the bug... it'll effectively consider (in your case) the triple to be full white.

vaab commented 7 years ago

For your interest, this is released and thus corrected, in v 0.1.4 and above.

vaab commented 7 years ago

For your interest, this is released and thus corrected, in v 0.1.4 and above.