[mutter/gnome-3-38] region-utils: Always use FLT_EPSILON when comparing floating point values
- From: Robert Mader <rmader src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gnome-3-38] region-utils: Always use FLT_EPSILON when comparing floating point values
- Date: Thu, 19 Nov 2020 20:19:46 +0000 (UTC)
commit c8f1e85298b89a8b49e7ae35d774a047426cbf47
Author: Robert Mader <robert mader posteo de>
Date: Mon Nov 16 13:51:43 2020 +0100
region-utils: Always use FLT_EPSILON when comparing floating point values
As you should always do. Using the `float` variant even if `scale` is
a `double` as values passed in are potentially computed at `float`
precission.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1565>
(cherry picked from commit 09b1bbb1cf64ec5e90396d4cedd4bbd84df899a1)
src/compositor/region-utils.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c
index aabe76b52d..02415cefbc 100644
--- a/src/compositor/region-utils.c
+++ b/src/compositor/region-utils.c
@@ -196,7 +196,7 @@ meta_region_scale_double (cairo_region_t *region,
g_return_val_if_fail (scale > 0.0, NULL);
- if (scale == 1.0)
+ if (G_APPROX_VALUE (scale, 1.f, FLT_EPSILON))
return cairo_region_copy (region);
n_rects = cairo_region_num_rectangles (region);
@@ -419,14 +419,17 @@ meta_region_crop_and_scale (cairo_region_t *region,
cairo_rectangle_int_t *rects;
cairo_region_t *viewport_region;
- if (src_rect->size.width == dst_width &&
- src_rect->size.height == dst_height &&
- roundf (src_rect->origin.x) == src_rect->origin.x &&
- roundf (src_rect->origin.y) == src_rect->origin.y)
+ if (G_APPROX_VALUE (src_rect->size.width, dst_width, FLT_EPSILON) &&
+ G_APPROX_VALUE (src_rect->size.height, dst_height, FLT_EPSILON) &&
+ G_APPROX_VALUE (roundf (src_rect->origin.x),
+ src_rect->origin.x, FLT_EPSILON) &&
+ G_APPROX_VALUE (roundf (src_rect->origin.y),
+ src_rect->origin.y, FLT_EPSILON))
{
viewport_region = cairo_region_copy (region);
- if (src_rect->origin.x != 0 || src_rect->origin.y != 0)
+ if (G_APPROX_VALUE (src_rect->origin.x, 0, FLT_EPSILON) ||
+ G_APPROX_VALUE (src_rect->origin.y, 0, FLT_EPSILON))
{
cairo_region_translate (viewport_region,
(int) src_rect->origin.x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]