From 8bc8dc66f234c223e1fb3ab545a540cb6ccc73d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 1 Mar 2019 02:49:19 +0100 Subject: [PATCH] clutter/rect: Clamp to pixel taking care of subpixel values The clamped rectangle currently could not fully contain the original fractional rectangle because it doesn't take care of the fact that the new width should consider the fact that flooring we'd translate the rectangle, and thus to cover the same area we need to take care of it. So, to properly compute the width and height, calculate x2 and y2 first and then use this ceiled value to compute the actual width using the floored x1 and y1. https://gitlab.gnome.org/GNOME/mutter/merge_requests/3 --- clutter/clutter/clutter-base-types.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clutter/clutter/clutter-base-types.c b/clutter/clutter/clutter-base-types.c index ba38d7e34..f7ad5261e 100644 --- a/clutter/clutter/clutter-base-types.c +++ b/clutter/clutter/clutter-base-types.c @@ -1160,15 +1160,20 @@ clutter_rect_inset (ClutterRect *rect, void clutter_rect_clamp_to_pixel (ClutterRect *rect) { + float x2, y2; + g_return_if_fail (rect != NULL); clutter_rect_normalize_internal (rect); + x2 = rect->origin.x + rect->size.width; + y2 = rect->origin.y + rect->size.height; + rect->origin.x = floorf (rect->origin.x); rect->origin.y = floorf (rect->origin.y); - rect->size.width = ceilf (rect->size.width); - rect->size.height = ceilf (rect->size.height); + rect->size.width = ceilf (x2) - rect->origin.x; + rect->size.height = ceilf (y2) - rect->origin.y; } /**