Skip to content

Commit b22c070

Browse files
committed
Use epsilon for comparison
1 parent 2ff6c34 commit b22c070

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/scenic/color.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ defmodule Scenic.Color do
224224
@hsv :color_hsv
225225
@hsl :color_hsl
226226

227+
# Epsilon value from JS
228+
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON
229+
@epsilon 2.22044e-16
230+
227231
@type implicit ::
228232
atom
229233
| {name :: atom, a :: integer}
@@ -534,9 +538,9 @@ defmodule Scenic.Color do
534538
l = (max + min) / 2
535539

536540
s =
537-
case delta do
538-
0.0 -> 0.0
539-
d -> d / (1 - abs(2 * l - 1))
541+
cond do
542+
delta < @epsilon -> 0.0
543+
true -> delta / (1 - abs(2 * l - 1))
540544
end
541545

542546
{h, s * 100, l * 100}

0 commit comments

Comments
 (0)