Mercurial > MadButterfly
comparison src/coord.c @ 13:ed55009d96d3
refactory for redrawing
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 31 Jul 2008 08:10:00 +0800 |
parents | 79e9edf4c00a |
children | c2ce186a5c37 |
comparison
equal
deleted
inserted
replaced
12:79e9edf4c00a | 13:ed55009d96d3 |
---|---|
100 co->aggr_matrix[5]); | 100 co->aggr_matrix[5]); |
101 *x = nx; | 101 *x = nx; |
102 *y = ny; | 102 *y = ny; |
103 } | 103 } |
104 | 104 |
105 coord_t *preorder_coord_tree(coord_t *last) { | 105 coord_t *preorder_coord_subtree(coord_t *root, coord_t *last) { |
106 coord_t *next; | 106 coord_t *next; |
107 | 107 |
108 ASSERT(last == NULL); | 108 ASSERT(last == NULL); |
109 | 109 |
110 if(STAILQ_HEAD(last->children)) | 110 if(STAILQ_HEAD(last->children)) |
111 next = STAILQ_HEAD(last->children); | 111 next = STAILQ_HEAD(last->children); |
112 else { | 112 else { |
113 next = last; | 113 next = last; |
114 while(next != NULL && STAILQ_NEXT(coord_t, sibling, next) == NULL) | 114 while(next != root && STAILQ_NEXT(coord_t, sibling, next) == NULL) |
115 next = next->parent; | 115 next = next->parent; |
116 if(next == root) | |
117 next = NULL; | |
116 if(next) | 118 if(next) |
117 next = STAILQ_NEXT(coord_t, sibling, next); | 119 next = STAILQ_NEXT(coord_t, sibling, next); |
118 } | 120 } |
119 | 121 |
120 return next; | 122 return next; |
191 coord_trans_pos(elms + 5, &x, &y); | 193 coord_trans_pos(elms + 5, &x, &y); |
192 CU_ASSERT(x == 1); | 194 CU_ASSERT(x == 1); |
193 CU_ASSERT(y == 99); | 195 CU_ASSERT(y == 99); |
194 } | 196 } |
195 | 197 |
196 void test_preorder_coord_tree(void) { | 198 void test_preorder_coord_subtree(void) { |
197 coord_t elms[6]; | 199 coord_t elms[6]; |
198 coord_t *last; | 200 coord_t *last; |
199 | 201 |
200 coord_init(elms, NULL); | 202 coord_init(elms, NULL); |
201 coord_init(elms + 1, elms); | 203 coord_init(elms + 1, elms); |
203 coord_init(elms + 3, elms + 1); | 205 coord_init(elms + 3, elms + 1); |
204 coord_init(elms + 4, elms + 1); | 206 coord_init(elms + 4, elms + 1); |
205 coord_init(elms + 5, elms + 2); | 207 coord_init(elms + 5, elms + 2); |
206 | 208 |
207 last = elms; | 209 last = elms; |
208 last = preorder_coord_tree(last); | 210 last = preorder_coord_subtree(elms, last); |
209 CU_ASSERT(last == elms + 1); | 211 CU_ASSERT(last == elms + 1); |
210 last = preorder_coord_tree(last); | 212 last = preorder_coord_subtree(elms, last); |
211 CU_ASSERT(last == elms + 3); | 213 CU_ASSERT(last == elms + 3); |
212 last = preorder_coord_tree(last); | 214 last = preorder_coord_subtree(elms, last); |
213 CU_ASSERT(last == elms + 4); | 215 CU_ASSERT(last == elms + 4); |
214 last = preorder_coord_tree(last); | 216 last = preorder_coord_subtree(elms, last); |
215 CU_ASSERT(last == elms + 2); | 217 CU_ASSERT(last == elms + 2); |
216 last = preorder_coord_tree(last); | 218 last = preorder_coord_subtree(elms, last); |
217 CU_ASSERT(last == elms + 5); | 219 CU_ASSERT(last == elms + 5); |
218 last = preorder_coord_tree(last); | 220 last = preorder_coord_subtree(elms, last); |
219 CU_ASSERT(last == NULL); | 221 CU_ASSERT(last == NULL); |
220 } | 222 } |
221 | 223 |
222 CU_pSuite get_coord_suite(void) { | 224 CU_pSuite get_coord_suite(void) { |
223 CU_pSuite suite; | 225 CU_pSuite suite; |
224 | 226 |
225 suite = CU_add_suite("Suite_coord", NULL, NULL); | 227 suite = CU_add_suite("Suite_coord", NULL, NULL); |
226 CU_ADD_TEST(suite, test_update_aggr_matrix); | 228 CU_ADD_TEST(suite, test_update_aggr_matrix); |
227 CU_ADD_TEST(suite, test_preorder_coord_tree); | 229 CU_ADD_TEST(suite, test_preorder_coord_subtree); |
228 | 230 |
229 return suite; | 231 return suite; |
230 } | 232 } |
231 | 233 |
232 #endif | 234 #endif |