clutter/brightness-contrast-effect: Compare float with G_APPROX_VALUE

Nobody should ever compare float for equality. Use G_APPROX_VALUE to
check that.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/992
This commit is contained in:
Georges Basile Stavracas Neto 2020-01-07 13:59:50 -03:00
parent 64685f4b20
commit 84ea4ad990

View File

@ -121,12 +121,12 @@ G_DEFINE_TYPE (ClutterBrightnessContrastEffect,
static gboolean static gboolean
will_have_no_effect (ClutterBrightnessContrastEffect *self) will_have_no_effect (ClutterBrightnessContrastEffect *self)
{ {
return (self->brightness_red == no_change && return (G_APPROX_VALUE (self->brightness_red, no_change, FLT_EPSILON) &&
self->brightness_green == no_change && G_APPROX_VALUE (self->brightness_green, no_change, FLT_EPSILON) &&
self->brightness_blue == no_change && G_APPROX_VALUE (self->brightness_blue, no_change, FLT_EPSILON) &&
self->contrast_red == no_change && G_APPROX_VALUE (self->contrast_red, no_change, FLT_EPSILON) &&
self->contrast_green == no_change && G_APPROX_VALUE (self->contrast_green, no_change, FLT_EPSILON) &&
self->contrast_blue == no_change); G_APPROX_VALUE (self->contrast_blue, no_change, FLT_EPSILON));
} }
static gboolean static gboolean
@ -497,9 +497,9 @@ clutter_brightness_contrast_effect_set_brightness_full (ClutterBrightnessContras
{ {
g_return_if_fail (CLUTTER_IS_BRIGHTNESS_CONTRAST_EFFECT (effect)); g_return_if_fail (CLUTTER_IS_BRIGHTNESS_CONTRAST_EFFECT (effect));
if (red == effect->brightness_red && if (G_APPROX_VALUE (red, effect->brightness_red, FLT_EPSILON) &&
green == effect->brightness_green && G_APPROX_VALUE (green, effect->brightness_green, FLT_EPSILON) &&
blue == effect->brightness_blue) G_APPROX_VALUE (blue, effect->brightness_blue, FLT_EPSILON))
return; return;
effect->brightness_red = red; effect->brightness_red = red;
@ -587,9 +587,9 @@ clutter_brightness_contrast_effect_set_contrast_full (ClutterBrightnessContrastE
{ {
g_return_if_fail (CLUTTER_IS_BRIGHTNESS_CONTRAST_EFFECT (effect)); g_return_if_fail (CLUTTER_IS_BRIGHTNESS_CONTRAST_EFFECT (effect));
if (red == effect->contrast_red && if (G_APPROX_VALUE (red, effect->contrast_red, FLT_EPSILON) &&
green == effect->contrast_green && G_APPROX_VALUE (green, effect->contrast_green, FLT_EPSILON) &&
blue == effect->contrast_blue) G_APPROX_VALUE (blue, effect->contrast_blue, FLT_EPSILON))
return; return;
effect->contrast_red = red; effect->contrast_red = red;