summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Mader <robert.mader@posteo.de>2020-11-16 13:51:43 +0100
committerRobert Mader <robert.mader@posteo.de>2020-11-19 21:06:36 +0100
commitc8f1e85298b89a8b49e7ae35d774a047426cbf47 (patch)
treed77c5bfda04d1c203efb9625549dcd69ab159847
parent2dc9bdb19302601d3302d228050ff421b6eb92d6 (diff)
downloadmutter-c8f1e85298b89a8b49e7ae35d774a047426cbf47.tar.gz
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)
-rw-r--r--src/compositor/region-utils.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c
index aabe76b52..02415cefb 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,