diff options
| author | Robert Mader <robert.mader@posteo.de> | 2020-11-16 13:51:43 +0100 |
|---|---|---|
| committer | Robert Mader <robert.mader@posteo.de> | 2020-11-16 19:27:20 +0100 |
| commit | 09b1bbb1cf64ec5e90396d4cedd4bbd84df899a1 (patch) | |
| tree | 5176ea6c2c05a6c9c038b8d681f00e1cf6bd598c /src | |
| parent | 91c9416259f744a9f1ae123a1f319943705ff23d (diff) | |
| download | mutter-09b1bbb1cf64ec5e90396d4cedd4bbd84df899a1.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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/compositor/region-utils.c | 15 |
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, |
