cedric pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=4e9656feacee2e00785d21d68bed5d3400c198be
commit 4e9656feacee2e00785d21d68bed5d3400c198be Author: Marcel Hollerbach <marcel-hollerb...@t-online.de> Date: Tue Dec 20 16:04:29 2016 -0800 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 <ced...@osg.samsung.com> --- src/lib/eina/eina_rectangle.c | 17 +++++++++++++++++ src/lib/eina/eina_rectangle.h | 24 ++++++++++++++++++++++++ src/tests/eina/eina_test_rectangle.c | 18 ++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/lib/eina/eina_rectangle.c b/src/lib/eina/eina_rectangle.c index 4a235da..a3e8bff 100644 --- a/src/lib/eina/eina_rectangle.c +++ b/src/lib/eina/eina_rectangle.c @@ -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; +} diff --git a/src/lib/eina/eina_rectangle.h b/src/lib/eina/eina_rectangle.h index 2b600c6..fce0470 100644 --- a/src/lib/eina/eina_rectangle.h +++ b/src/lib/eina/eina_rectangle.h @@ -75,6 +75,19 @@ typedef enum { } 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. * * @param c1 The column of the first span. @@ -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" /** diff --git a/src/tests/eina/eina_test_rectangle.c b/src/tests/eina/eina_test_rectangle.c index fe21bf7..a6891f3 100644 --- a/src/tests/eina/eina_test_rectangle.c +++ b/src/tests/eina/eina_test_rectangle.c @@ -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); } --