eina: Eina_Tiler - return a NULL if intersection of two tilers doesn't exist

Summary:
change eina_tiler_intersection to return a NULL if intersection
of two tilers doesn't exist. and add test case to check it.

This doesn't break ABI/API as this call could already return a NULL value and it
should have been handled by the caller anyway. This just make an expected behavior
more correct.

Test Plan: run eina_suite after building eina test suite

Reviewers: cedric, raster, torori, devilhorns

Subscribers: cedric

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

Signed-off-by: Cedric BAIL <c.bail@partner.samsung.com>
This commit is contained in:
Gwanglim Lee 2014-07-21 19:27:09 +02:00 committed by Cedric BAIL
parent 3b8a03cf7b
commit 3d534e87c3
3 changed files with 20 additions and 7 deletions

View File

@ -1444,10 +1444,6 @@ eina_tiler_intersection(Eina_Tiler *t1,
if (!(eina_rectangles_intersect(&t1->area, &t2->area)))
return NULL;
w = MIN(t1->area.w, t2->area.w);
h = MIN(t1->area.h, t2->area.h);
t = eina_tiler_new(w, h);
itr1 = eina_tiler_iterator_new(t1);
itr2 = eina_tiler_iterator_new(t2);
@ -1459,6 +1455,10 @@ eina_tiler_intersection(Eina_Tiler *t1,
if ((!eina_iterator_next(itr2, (void**)(void*)(&rect2))) && (!rect2))
goto cleanup;
w = MIN(t1->area.w, t2->area.w);
h = MIN(t1->area.h, t2->area.h);
t = eina_tiler_new(w, h);
while((rect1) && (rect2))
{
if (eina_rectangles_intersect(rect1, rect2))
@ -1498,6 +1498,12 @@ eina_tiler_intersection(Eina_Tiler *t1,
break;
}
if (eina_tiler_empty(t))
{
eina_tiler_free(t);
t = NULL;
}
cleanup:
eina_iterator_free(itr1);
eina_iterator_free(itr2);

View File

@ -338,10 +338,10 @@ EAPI Eina_Bool eina_tiler_subtract(Eina_Tiler *dst, Eina_Tiler *src);
*
* @param t1 The first tile.
* @param t2 The second tiler.
* @return A pointer of intersection result. @c NULL on failure.
* @return A pointer of intersection result. @c NULL if intersection doesn't exist.
*
* This fuction gest intersection of two tilers @p t1 and @p t2.
* It returns a pointer of result if it succeeds., otherwise returns NULL.
* It returns a pointer of result if intersection of two tilers exists., otherwise returns NULL.
*/
EAPI Eina_Tiler *eina_tiler_intersection(Eina_Tiler *t1, Eina_Tiler *t2);

View File

@ -224,7 +224,7 @@ START_TEST(eina_test_tiler_calculation)
{
Eina_Tiler *t1, *t2, *t;
Eina_Iterator *itr;
Eina_Rectangle r1, r2, *rp;
Eina_Rectangle r1, r2, r3, *rp;
int i = 0;
eina_init();
@ -288,6 +288,13 @@ START_TEST(eina_test_tiler_calculation)
fail_if(i != 4);
EINA_RECTANGLE_SET(&r3, 0, 0, 50, 50);
eina_tiler_rect_add(t1, &r3);
t = eina_tiler_intersection(t1, t2);
fail_if(t);
eina_tiler_clear(t1);
eina_tiler_rect_add(t1, &r1);