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>
This commit is contained in:
Robert Mader 2020-11-16 13:51:43 +01:00
parent 91c9416259
commit 09b1bbb1cf

View File

@ -196,7 +196,7 @@ meta_region_scale_double (cairo_region_t *region,
g_return_val_if_fail (scale > 0.0, NULL); 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); return cairo_region_copy (region);
n_rects = cairo_region_num_rectangles (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_rectangle_int_t *rects;
cairo_region_t *viewport_region; cairo_region_t *viewport_region;
if (src_rect->size.width == dst_width && if (G_APPROX_VALUE (src_rect->size.width, dst_width, FLT_EPSILON) &&
src_rect->size.height == dst_height && G_APPROX_VALUE (src_rect->size.height, dst_height, FLT_EPSILON) &&
roundf (src_rect->origin.x) == src_rect->origin.x && G_APPROX_VALUE (roundf (src_rect->origin.x),
roundf (src_rect->origin.y) == src_rect->origin.y) 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); 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, cairo_region_translate (viewport_region,
(int) src_rect->origin.x, (int) src_rect->origin.x,