mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
Use an epsilon for float comparison
We tend to use float comparison for structured data types like Vertex, Point, and Size; we should take into consideration fluctuations in the floating point representation as well.
This commit is contained in:
parent
695621f5ea
commit
9c637ccb41
@ -39,6 +39,8 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#define FLOAT_EPSILON (1e-15)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -277,9 +279,9 @@ clutter_vertex_equal (const ClutterVertex *vertex_a,
|
|||||||
if (vertex_a == vertex_b)
|
if (vertex_a == vertex_b)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return vertex_a->x == vertex_b->x &&
|
return fabsf (vertex_a->x - vertex_b->x) < FLOAT_EPSILON &&
|
||||||
vertex_a->y == vertex_b->y &&
|
fabsf (vertex_a->y - vertex_b->y) < FLOAT_EPSILON &&
|
||||||
vertex_a->z == vertex_b->z;
|
fabsf (vertex_a->z - vertex_b->z) < FLOAT_EPSILON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -469,7 +471,8 @@ clutter_point_equals (const ClutterPoint *a,
|
|||||||
if (a == NULL || b == NULL)
|
if (a == NULL || b == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return a->x == b->x && a->y == b->y;
|
return fabsf (a->x - b->x) < FLOAT_EPSILON &&
|
||||||
|
fabsf (a->y - b->y) < FLOAT_EPSILON;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -636,7 +639,8 @@ clutter_size_equals (const ClutterSize *a,
|
|||||||
if (a == NULL || b == NULL)
|
if (a == NULL || b == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return a->width == b->width && a->height == b->height;
|
return fabsf (a->width - b->width) < FLOAT_EPSILON &&
|
||||||
|
fabsf (a->height - b->height) < FLOAT_EPSILON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user