Commit da3b4127 authored by Téo Mazars's avatar Téo Mazars

extensions: Don't perform strict comparisons on floating point values

parent 6a3ef341
......@@ -25,6 +25,7 @@
#define MIN(a,b) ((a > b) ? b : a)
#define MAX(a,b) ((a < b) ? b : a)
#define EPSILON 1.0e-10
static long rgba_to_hsla (char *src,
char *dst,
......@@ -121,16 +122,16 @@ rgb_to_hsl_step (double* src,
max = MAX (red, MAX (green, blue));
min = MIN (red, MIN (green, blue));
if (max == red)
if (max - red < EPSILON)
cpn_max = 0;
else if (max == green)
else if (max - green < EPSILON)
cpn_max = 1;
else
cpn_max = 2;
lightness = (max + min) / 2.0;
if (max == min)
if (max - min < EPSILON)
{
hue = saturation = 0;
}
......
......@@ -30,6 +30,7 @@
#define MIN(a,b) (a > b) ? b : a;
#define MAX(a,b) (a < b) ? b : a;
#define EPSILON 1.0e-10
static long rgba_to_hsva (char *src,
char *dst,
......@@ -183,25 +184,25 @@ rgba_to_hsv_step (char *src,
chroma = value - min;
if (value == 0.0)
if (value < EPSILON)
saturation = 0.0;
else
saturation = chroma / value;
if (saturation == 0.0)
if (saturation < EPSILON)
{
hue = 0.0;
}
else
{
if (red == value)
if (fabs (red - value) < EPSILON)
{
hue = (green - blue) / chroma;
if (hue < 0.0)
hue += 6.0;
}
else if (green == value)
else if (fabs (green - value) < EPSILON)
hue = 2.0 + (blue - red) / chroma;
else
hue = 4.0 + (red - green) / chroma;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment