From b19332a0bec7bb121ec62285b942ce880e547a95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 3 Mar 2010 15:45:43 +0000 Subject: [PATCH] animator: compare floating point values with an epsilon Direct comparisons with doubles are error prone. --- clutter/clutter-animator.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/clutter/clutter-animator.c b/clutter/clutter-animator.c index a698415..21cbbe0 100644 --- a/clutter/clutter-animator.c +++ b/clutter/clutter-animator.c @@ -139,6 +139,9 @@ #define CLUTTER_ANIMATOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_ANIMATOR, ClutterAnimatorPrivate)) +/* progress values varying by less than this are considered equal */ +#define PROGRESS_EPSILON 0.00001 + struct _ClutterAnimatorPrivate { ClutterTimeline *timeline; @@ -325,7 +328,7 @@ sort_actor_prop_progress_func (gconstpointer a, if (pdiff) return pdiff; - if (pa->progress == pb->progress) + if (fabs (pa->progress - pb->progress) < PROGRESS_EPSILON) return 0; if (pa->progress > pb->progress) @@ -1346,7 +1349,7 @@ clutter_animator_get_keys (ClutterAnimator *animator, if ((object == NULL || (object == key->object)) && (property_name == NULL || ((property_name == key->property_name))) && - (progress < 0 || (progress == key->progress))) + (progress < 0 || fabs (progress - key->progress) < PROGRESS_EPSILON)) { keys = g_list_prepend (keys, key); } @@ -1390,7 +1393,7 @@ clutter_animator_remove_key (ClutterAnimator *animator, if ((object == NULL || (object == key->object)) && (property_name == NULL || ((property_name == key->property_name))) && - (progress < 0 || (progress == key->progress)) + (progress < 0 || fabs (progress - key->progress) < PROGRESS_EPSILON) ) { key->is_inert = TRUE; -- 2.7.4