From db7775993889a596035f146b8edc3a365620dee5 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Thu, 20 Jul 2023 00:44:52 +0200 Subject: [PATCH] mtk: Move Rectangle.area from Meta Part-of: --- mtk/mtk/mtk-rectangle.c | 13 +++++++++++++ mtk/mtk/mtk-rectangle.h | 4 ++++ src/backends/meta-monitor-manager.c | 2 +- src/core/boxes.c | 14 +++----------- src/meta/boxes.h | 4 ---- src/tests/boxes-tests.c | 10 +++++----- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/mtk/mtk/mtk-rectangle.c b/mtk/mtk/mtk-rectangle.c index e70a93a9a..b8003fbac 100644 --- a/mtk/mtk/mtk-rectangle.c +++ b/mtk/mtk/mtk-rectangle.c @@ -63,6 +63,19 @@ mtk_rectangle_new (int x, return rect; } +/** + * mtk_rectangle_area: + * @rect: A rectangle + * + * Returns: The area of the rectangle + */ +int +mtk_rectangle_area (const MtkRectangle *rect) +{ + g_return_val_if_fail (rect != NULL, 0); + return rect->width * rect->height; +} + /** * mtk_rectangle_equal: * @src1: The first rectangle diff --git a/mtk/mtk/mtk-rectangle.h b/mtk/mtk/mtk-rectangle.h index 435cbb08f..3f923b6c6 100644 --- a/mtk/mtk/mtk-rectangle.h +++ b/mtk/mtk/mtk-rectangle.h @@ -79,6 +79,10 @@ MtkRectangle * mtk_rectangle_new (int x, int width, int height); +/* Basic comparison functions */ +MTK_EXPORT +int mtk_rectangle_area (const MtkRectangle *rect); + MTK_EXPORT gboolean mtk_rectangle_equal (const MtkRectangle *src1, const MtkRectangle *src2); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index f25ef870c..f46129f07 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -3374,7 +3374,7 @@ meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager, &intersection)) continue; - intersection_area = meta_rectangle_area (&intersection); + intersection_area = mtk_rectangle_area (&intersection); if (intersection_area > best_logical_monitor_area) { diff --git a/src/core/boxes.c b/src/core/boxes.c index e24efb098..181d8b42c 100644 --- a/src/core/boxes.c +++ b/src/core/boxes.c @@ -133,14 +133,6 @@ meta_rectangle_edge_list_to_string (GList *edge_list, return output; } - -int -meta_rectangle_area (const MetaRectangle *rect) -{ - g_return_val_if_fail (rect != NULL, 0); - return rect->width * rect->height; -} - gboolean meta_rectangle_overlap (const MetaRectangle *rect1, const MetaRectangle *rect2) @@ -402,8 +394,8 @@ compare_rect_areas (gconstpointer a, gconstpointer b) const MetaRectangle *a_rect = (gconstpointer) a; const MetaRectangle *b_rect = (gconstpointer) b; - int a_area = meta_rectangle_area (a_rect); - int b_area = meta_rectangle_area (b_rect); + int a_area = mtk_rectangle_area (a_rect); + int b_area = mtk_rectangle_area (b_rect); return b_area - a_area; /* positive ret value denotes b > a, ... */ } @@ -890,7 +882,7 @@ meta_rectangle_clip_to_region (const GList *spanning_rects, /* Determine maximal overlap amount */ mtk_rectangle_intersect (rect, compare_rect, &overlap); - maximal_overlap_amount_for_compare = meta_rectangle_area (&overlap); + maximal_overlap_amount_for_compare = mtk_rectangle_area (&overlap); /* See if this is the best rect so far */ if (maximal_overlap_amount_for_compare > best_overlap) diff --git a/src/meta/boxes.h b/src/meta/boxes.h index c3278fc3d..daa576602 100644 --- a/src/meta/boxes.h +++ b/src/meta/boxes.h @@ -101,10 +101,6 @@ MetaRectangle *meta_rectangle_copy (const MetaRectangle *rect); META_EXPORT void meta_rectangle_free (MetaRectangle *rect); -/* Basic comparison functions */ -META_EXPORT -int meta_rectangle_area (const MetaRectangle *rect); - /* overlap is similar to intersect but doesn't provide location of * intersection information. */ diff --git a/src/tests/boxes-tests.c b/src/tests/boxes-tests.c index 44a8e8068..c47f89e82 100644 --- a/src/tests/boxes-tests.c +++ b/src/tests/boxes-tests.c @@ -110,11 +110,11 @@ test_area (void) for (i = 0; i < NUM_RANDOM_RUNS; i++) { get_random_rect (&temp); - g_assert (meta_rectangle_area (&temp) == temp.width * temp.height); + g_assert (mtk_rectangle_area (&temp) == temp.width * temp.height); } temp = MTK_RECTANGLE_INIT (0, 0, 5, 7); - g_assert (meta_rectangle_area (&temp) == 35); + g_assert (mtk_rectangle_area (&temp) == 35); } static void @@ -131,13 +131,13 @@ test_intersect (void) mtk_rectangle_intersect (&a, &b, &temp); temp2 = MTK_RECTANGLE_INIT (100, 200, 10, 2); g_assert (mtk_rectangle_equal (&temp, &temp2)); - g_assert (meta_rectangle_area (&temp) == 20); + g_assert (mtk_rectangle_area (&temp) == 20); mtk_rectangle_intersect (&a, &c, &temp); - g_assert (meta_rectangle_area (&temp) == 0); + g_assert (mtk_rectangle_area (&temp) == 0); mtk_rectangle_intersect (&a, &d, &temp); - g_assert (meta_rectangle_area (&temp) == 0); + g_assert (mtk_rectangle_area (&temp) == 0); mtk_rectangle_intersect (&b, &d, &b); g_assert (mtk_rectangle_equal (&b, &b_intersect_d));