eina: add api for assessing the relative position of two rectangles

Summary:
the api returns if a rectangle is positioned above/below/right or left
of a other rectangle.

Code which does simular things are part of verne and e, i think its a good idea to provide api for that.

Test Plan: Just run the test suite

Reviewers: raster, jpeg, cedric

Reviewed By: cedric

Differential Revision: https://phab.enlightenment.org/D4489

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Marcel Hollerbach 2016-12-20 16:04:29 -08:00 committed by Cedric BAIL
parent a5804c970d
commit 4e9656feac
3 changed files with 59 additions and 0 deletions

View File

@ -894,3 +894,20 @@ eina_rectangle_pool_geometry_get(Eina_Rectangle_Pool *pool, int *w, int *h)
return EINA_TRUE;
}
EAPI Eina_Rectangle_Outside
eina_rectangle_outside_position(Eina_Rectangle *rect1, Eina_Rectangle *rect2)
{
Eina_Rectangle_Outside ret = 0;
if (rect1->y > rect2->y)
ret |= EINA_RECTANGLE_OUTSIDE_TOP;
if (rect1->x > rect2->x)
ret |= EINA_RECTANGLE_OUTSIDE_LEFT;
if (rect1->y + rect1->h < rect2->y + rect2->h)
ret |= EINA_RECTANGLE_OUTSIDE_BOTTOM;
if (rect1->x + rect1->w < rect2->x + rect2->w)
ret |= EINA_RECTANGLE_OUTSIDE_RIGHT;
return ret;
}

View File

@ -74,6 +74,19 @@ typedef enum {
Eina_Packing_Bottom_Left_Skyline_Improved /**< optimized bottemleft skyline */
} Eina_Rectangle_Packing;
/**
* @typedef Eina_Rectangle_Outside
* Enumeration gives the positions where a rectangle can be outside a other rectangle
* @since 1.19
*/
typedef enum {
EINA_RECTANGLE_OUTSIDE_TOP = 1,
EINA_RECTANGLE_OUTSIDE_LEFT = 2,
EINA_RECTANGLE_OUTSIDE_BOTTOM = 4,
EINA_RECTANGLE_OUTSIDE_RIGHT = 8
} Eina_Rectangle_Outside;
/**
* @brief Check if the given spans intersect.
*
@ -507,6 +520,17 @@ EAPI void eina_rectangle_free(Eina_Rectangle *rect) EINA_ARG_NONNULL(
*/
EAPI void eina_rectangle_pool_packing_set(Eina_Rectangle_Pool *pool,Eina_Rectangle_Packing type) EINA_ARG_NONNULL(1);
/**
* @brief calculate where rect2 is outside of rect1
*
* @param rect1 the rect to use as anchor
* @param rect2 the rect to look for outside positions
*
* @return A or'ed map of Eina_Rectangle_Outside values
* @since 1.19
*/
EAPI Eina_Rectangle_Outside eina_rectangle_outside_position(Eina_Rectangle *rect1, Eina_Rectangle *rect2);
#include "eina_inline_rectangle.x"
/**

View File

@ -196,10 +196,28 @@ START_TEST(eina_rectangle_union_intersect)
}
END_TEST
START_TEST(eina_rectangle_position_test)
{
Eina_Rectangle middle, top, down, right, left;
EINA_RECTANGLE_SET(&middle, -1, -1, 2.0, 2.0);
EINA_RECTANGLE_SET(&top, -1, -2, 2.0, 2.0);
EINA_RECTANGLE_SET(&right, 0, -1, 2.0, 2.0);
EINA_RECTANGLE_SET(&left, -2, -1, 2.0, 2.0);
EINA_RECTANGLE_SET(&down, -1, 0, 2.0, 2.0);
ck_assert_int_eq(eina_rectangle_outside_position(&middle, &top), EINA_RECTANGLE_OUTSIDE_TOP) ;
ck_assert_int_eq(eina_rectangle_outside_position(&middle, &down), EINA_RECTANGLE_OUTSIDE_BOTTOM) ;
ck_assert_int_eq(eina_rectangle_outside_position(&middle, &right), EINA_RECTANGLE_OUTSIDE_RIGHT) ;
ck_assert_int_eq(eina_rectangle_outside_position(&middle, &left), EINA_RECTANGLE_OUTSIDE_LEFT) ;
}
END_TEST
void
eina_test_rectangle(TCase *tc)
{
tcase_add_test(tc, eina_rectangle_pool);
tcase_add_test(tc, eina_rectangle_pool_skyline);
tcase_add_test(tc, eina_rectangle_union_intersect);
tcase_add_test(tc, eina_rectangle_position_test);
}