mtk: Move Rectangle.area from Meta
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3128>
This commit is contained in:
parent
af7c7befd8
commit
db77759938
@ -63,6 +63,19 @@ mtk_rectangle_new (int x,
|
|||||||
return rect;
|
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:
|
* mtk_rectangle_equal:
|
||||||
* @src1: The first rectangle
|
* @src1: The first rectangle
|
||||||
|
@ -79,6 +79,10 @@ MtkRectangle * mtk_rectangle_new (int x,
|
|||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
|
|
||||||
|
/* Basic comparison functions */
|
||||||
|
MTK_EXPORT
|
||||||
|
int mtk_rectangle_area (const MtkRectangle *rect);
|
||||||
|
|
||||||
MTK_EXPORT
|
MTK_EXPORT
|
||||||
gboolean mtk_rectangle_equal (const MtkRectangle *src1,
|
gboolean mtk_rectangle_equal (const MtkRectangle *src1,
|
||||||
const MtkRectangle *src2);
|
const MtkRectangle *src2);
|
||||||
|
@ -3374,7 +3374,7 @@ meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
|
|||||||
&intersection))
|
&intersection))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
intersection_area = meta_rectangle_area (&intersection);
|
intersection_area = mtk_rectangle_area (&intersection);
|
||||||
|
|
||||||
if (intersection_area > best_logical_monitor_area)
|
if (intersection_area > best_logical_monitor_area)
|
||||||
{
|
{
|
||||||
|
@ -133,14 +133,6 @@ meta_rectangle_edge_list_to_string (GList *edge_list,
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
meta_rectangle_area (const MetaRectangle *rect)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (rect != NULL, 0);
|
|
||||||
return rect->width * rect->height;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
meta_rectangle_overlap (const MetaRectangle *rect1,
|
meta_rectangle_overlap (const MetaRectangle *rect1,
|
||||||
const MetaRectangle *rect2)
|
const MetaRectangle *rect2)
|
||||||
@ -402,8 +394,8 @@ compare_rect_areas (gconstpointer a, gconstpointer b)
|
|||||||
const MetaRectangle *a_rect = (gconstpointer) a;
|
const MetaRectangle *a_rect = (gconstpointer) a;
|
||||||
const MetaRectangle *b_rect = (gconstpointer) b;
|
const MetaRectangle *b_rect = (gconstpointer) b;
|
||||||
|
|
||||||
int a_area = meta_rectangle_area (a_rect);
|
int a_area = mtk_rectangle_area (a_rect);
|
||||||
int b_area = meta_rectangle_area (b_rect);
|
int b_area = mtk_rectangle_area (b_rect);
|
||||||
|
|
||||||
return b_area - a_area; /* positive ret value denotes b > a, ... */
|
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 */
|
/* Determine maximal overlap amount */
|
||||||
mtk_rectangle_intersect (rect, compare_rect, &overlap);
|
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 */
|
/* See if this is the best rect so far */
|
||||||
if (maximal_overlap_amount_for_compare > best_overlap)
|
if (maximal_overlap_amount_for_compare > best_overlap)
|
||||||
|
@ -101,10 +101,6 @@ MetaRectangle *meta_rectangle_copy (const MetaRectangle *rect);
|
|||||||
META_EXPORT
|
META_EXPORT
|
||||||
void meta_rectangle_free (MetaRectangle *rect);
|
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
|
/* overlap is similar to intersect but doesn't provide location of
|
||||||
* intersection information.
|
* intersection information.
|
||||||
*/
|
*/
|
||||||
|
@ -110,11 +110,11 @@ test_area (void)
|
|||||||
for (i = 0; i < NUM_RANDOM_RUNS; i++)
|
for (i = 0; i < NUM_RANDOM_RUNS; i++)
|
||||||
{
|
{
|
||||||
get_random_rect (&temp);
|
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);
|
temp = MTK_RECTANGLE_INIT (0, 0, 5, 7);
|
||||||
g_assert (meta_rectangle_area (&temp) == 35);
|
g_assert (mtk_rectangle_area (&temp) == 35);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -131,13 +131,13 @@ test_intersect (void)
|
|||||||
mtk_rectangle_intersect (&a, &b, &temp);
|
mtk_rectangle_intersect (&a, &b, &temp);
|
||||||
temp2 = MTK_RECTANGLE_INIT (100, 200, 10, 2);
|
temp2 = MTK_RECTANGLE_INIT (100, 200, 10, 2);
|
||||||
g_assert (mtk_rectangle_equal (&temp, &temp2));
|
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);
|
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);
|
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);
|
mtk_rectangle_intersect (&b, &d, &b);
|
||||||
g_assert (mtk_rectangle_equal (&b, &b_intersect_d));
|
g_assert (mtk_rectangle_equal (&b, &b_intersect_d));
|
||||||
|
Loading…
Reference in New Issue
Block a user