28
#include "eina_suite.h"
30
static Eina_Quad_Direction
31
_eina_quadtree_rectangle_vert(const void *object, size_t middle)
33
const Eina_Rectangle *r = object;
35
if (r->y + r->h < (int)middle)
36
return EINA_QUAD_LEFT;
38
if (r->y > (int)middle)
39
return EINA_QUAD_RIGHT;
41
return EINA_QUAD_BOTH;
44
static Eina_Quad_Direction
45
_eina_quadtree_rectangle_hort(const void *object, size_t middle)
47
const Eina_Rectangle *r = object;
49
if (r->x + r->w < (int)middle)
50
return EINA_QUAD_LEFT;
52
if (r->x > (int)middle)
53
return EINA_QUAD_RIGHT;
55
return EINA_QUAD_BOTH;
58
EFL_START_TEST(eina_quadtree_collision)
63
Eina_QuadTree_Item *item;
65
{ { 10, 10, 30, 30 }, NULL },
66
{ { 20, 20, 30, 30 }, NULL },
67
{ { 5, 30, 30, 30 }, NULL },
68
{ { 70, 130, 100, 100 }, NULL },
69
{ { 10, 220, 50, 40 }, NULL },
70
{ { 310, 20, 50, 30 }, NULL },
71
{ { 300, 220, 40, 40 }, NULL },
72
{ { 500, 150, 40, 40 }, NULL },
73
{ { 500, 220, 40, 40 }, NULL },
74
{ { 330, 250, 40, 40 }, NULL },
75
{ { 300, 400, 40, 40 }, NULL },
76
{ { 10, 400, 40, 40 }, NULL },
77
{ { 0, 0, 0, 0 }, NULL }
85
{ { 600, 400, 40, 40 }, 4, { 4, 6, 8, 10 } },
86
{ { 20, 30, 10, 10 }, 7, { 0, 1, 2, 4, 5, 6, 8 } },
87
{ { 0, 0, 0, 0 }, -1, {} },
89
int hidden[] = { 4, 5, 6, 8, 10 };
90
int show[] = { 0, 1, 2 };
98
q = eina_quadtree_new(640, 480,
99
_eina_quadtree_rectangle_vert,
100
_eina_quadtree_rectangle_hort);
104
for (i = 0; objects[i].r.w != 0 && objects[i].r.h != 0; ++i)
106
objects[i].item = eina_quadtree_add(q, &objects[i].r);
107
fail_if(!objects[i].item);
108
fail_if(!eina_quadtree_show(objects[i].item));
111
eina_quadtree_resize(q, 640, 480);
113
for (i = 0; tests[i].count != -1; ++i)
115
head = eina_quadtree_collide(q,
116
tests[i].r.x, tests[i].r.y,
117
tests[i].r.w, tests[i].r.h);
124
r = eina_quadtree_object(head);
126
for (k = 0; k < tests[i].count; ++k)
128
if (&objects[tests[i].result[k]].r == r)
131
fail_if(k == tests[i].count);
136
fail_if(count != tests[i].count);
139
for (i = 0; i < (int)(sizeof (hidden) / sizeof (int)); ++i)
140
eina_quadtree_hide(objects[hidden[i]].item);
141
for (i = 0; i < (int)(sizeof (show) / sizeof (int)); ++i)
142
eina_quadtree_show(objects[show[i]].item);
144
head = eina_quadtree_collide(q,
145
tests[1].r.x, tests[1].r.y,
146
tests[1].r.w, tests[1].r.h);
151
r = eina_quadtree_object(head);
153
fail_if(r != &objects[tests[1].result[show[count]]].r);
160
eina_quadtree_cycle(q);
161
eina_quadtree_show(objects[4].item);
162
eina_quadtree_increase(objects[4].item);
163
eina_quadtree_show(objects[5].item);
164
eina_quadtree_increase(objects[5].item);
165
eina_quadtree_del(objects[5].item);
166
eina_quadtree_change(objects[10].item);
167
eina_quadtree_increase(objects[10].item);
169
eina_quadtree_resize(q, 641, 480);
171
head = eina_quadtree_collide(q,
172
tests[0].r.x, tests[0].r.y,
173
tests[0].r.w, tests[0].r.h);
178
r = eina_quadtree_object(head);
185
eina_quadtree_free(q);
191
eina_test_quadtree(TCase *tc)
193
tcase_add_test(tc, eina_quadtree_collision);