Skip to content

Commit

Permalink
More stable HSL saturation calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Mar 21, 2021
1 parent 2284c9d commit bc339af
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coloraide/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,5 @@ def parse_version(ver):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(0, 1, 0, "alpha", 11)
__version_info__ = Version(0, 1, 0, "alpha", 12)
__version__ = __version_info__._get_canonical()
2 changes: 1 addition & 1 deletion coloraide/colors/hsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def srgb_to_hsl(rgb):
h = (b - r) / c + 2.0
else:
h = (r - g) / c + 4.0
s = 0 if l == 0 or l == 1 else c / (1.0 - abs(2.0 * l - 1))
s = 0 if l == 0 or l == 1 else (mx - l) / min(l, 1 - l)
h *= 60.0

return HSL._constrain_hue(h), s * 100.0, l * 100.0
Expand Down
6 changes: 6 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.1.0a12

- **FIX**: More stable saturation calculation for HSL to ensure divide by zero doesn't occur.
`2(V - L) / (1 - abs(2 * L - 1))` is likely to yield zero in the denominator when `L` is very small, while the
equivalent `(V - L) / min(L, 1 - L)` is not.

## 0.1.0a11

- **FIX**: Ensure that when `hex`, `compress`, and `names` is enabled in `to_string` for `srgb` that colors will still
Expand Down

0 comments on commit bc339af

Please sign in to comment.