Mercurial > MadButterfly
comparison src/geo.c @ 17:41f0907b27ac
Unittest for rdman_redraw_changed().
geo_init() is seperated into geo_init() and geo_from_positions().
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 01 Aug 2008 23:32:22 +0800 |
parents | c2ce186a5c37 |
children | 0f3baa488a62 |
comparison
equal
deleted
inserted
replaced
16:e17e12b112c4 | 17:41f0907b27ac |
---|---|
51 else if(y > max_y) | 51 else if(y > max_y) |
52 max_y = y; | 52 max_y = y; |
53 } | 53 } |
54 | 54 |
55 area->x = min_x; | 55 area->x = min_x; |
56 area->w = max_x - min_x; | 56 area->w = max_x - min_x + 1; |
57 area->y = min_y; | 57 area->y = min_y; |
58 area->h = max_y - min_y; | 58 area->h = max_y - min_y + 1; |
59 } | 59 } |
60 | 60 |
61 void geo_init(geo_t *g, int n_pos, co_aix pos[][2]) { | 61 void geo_init(geo_t *g) { |
62 memset(g, 0, sizeof(geo_t)); | |
62 g->cur_area = g->areas; | 63 g->cur_area = g->areas; |
63 g->last_area = g->areas + 1; | 64 g->last_area = g->areas + 1; |
65 } | |
66 | |
67 void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]) { | |
64 area_init(g->cur_area, n_pos, pos); | 68 area_init(g->cur_area, n_pos, pos); |
65 } | 69 } |
66 | 70 |
67 void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, | 71 void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, |
68 int *n_overlays, geo_t **overlays) { | 72 int *n_overlays, geo_t **overlays) { |
79 | 83 |
80 #ifdef UNITTEST | 84 #ifdef UNITTEST |
81 | 85 |
82 #include <CUnit/Basic.h> | 86 #include <CUnit/Basic.h> |
83 | 87 |
84 void test_geo_init(void) { | 88 void test_geo_from_positions(void) { |
85 co_aix data[][2] = { | 89 co_aix data[][2] = { |
86 {33, 25}, {49, 12}, | 90 {33, 25}, {49, 12}, |
87 {14, 28}, {39, 56}}; | 91 {14, 28}, {39, 56}}; |
88 geo_t g; | 92 geo_t g; |
89 | 93 |
90 geo_init(&g, 4, data); | 94 geo_init(&g); |
95 geo_from_positions(&g, 4, data); | |
91 CU_ASSERT(g.cur_area->x == 14); | 96 CU_ASSERT(g.cur_area->x == 14); |
92 CU_ASSERT(g.cur_area->w == 35); | 97 CU_ASSERT(g.cur_area->w == 36); |
93 CU_ASSERT(g.cur_area->y == 12); | 98 CU_ASSERT(g.cur_area->y == 12); |
94 CU_ASSERT(g.cur_area->h == 44); | 99 CU_ASSERT(g.cur_area->h == 45); |
95 } | 100 } |
96 | 101 |
97 void test_geo_mark_overlay(void) { | 102 void test_geo_mark_overlay(void) { |
98 geo_t _geos[3], *geos[3], *overlays[3]; | 103 geo_t _geos[3], *geos[3], *overlays[3]; |
99 geo_t g; | 104 geo_t g; |
103 for(i = 0; i < 3; i++) { | 108 for(i = 0; i < 3; i++) { |
104 pos[0][0] = i * 50; | 109 pos[0][0] = i * 50; |
105 pos[0][1] = i * 50; | 110 pos[0][1] = i * 50; |
106 pos[1][0] = i * 50 + 55; | 111 pos[1][0] = i * 50 + 55; |
107 pos[1][1] = i * 50 + 66; | 112 pos[1][1] = i * 50 + 66; |
108 geo_init(_geos + i, 2, pos); | 113 geo_init(_geos + i); |
114 geo_from_positions(_geos + i, 2, pos); | |
109 geos[i] = _geos + i; | 115 geos[i] = _geos + i; |
110 } | 116 } |
111 pos[0][0] = 88; | 117 pos[0][0] = 88; |
112 pos[0][1] = 79; | 118 pos[0][1] = 79; |
113 pos[1][0] = 88 + 70; | 119 pos[1][0] = 88 + 70; |
114 pos[1][1] = 79 + 70; | 120 pos[1][1] = 79 + 70; |
115 geo_init(&g, 2, pos); | 121 geo_init(&g); |
122 geo_from_positions(&g, 2, pos); | |
116 | 123 |
117 /* overlay with geos[1] and geos[2] */ | 124 /* overlay with geos[1] and geos[2] */ |
118 geo_mark_overlay(&g, 3, geos, &n_ov, overlays); | 125 geo_mark_overlay(&g, 3, geos, &n_ov, overlays); |
119 CU_ASSERT(n_ov == 2); | 126 CU_ASSERT(n_ov == 2); |
120 CU_ASSERT(overlays[0] == geos[1]); | 127 CU_ASSERT(overlays[0] == geos[1]); |
121 CU_ASSERT(overlays[1] == geos[2]); | 128 CU_ASSERT(overlays[1] == geos[2]); |
122 | 129 |
123 /* right side of geos[1], and up side of geos[2] */ | 130 /* right side of geos[1], and up side of geos[2] */ |
124 pos[0][0] = 105; | 131 pos[0][0] = 106; |
125 pos[0][1] = 50; | 132 pos[0][1] = 51; |
126 pos[1][0] = 105 + 50; | 133 pos[1][0] = 106 + 49; |
127 pos[1][1] = 50 + 51; | 134 pos[1][1] = 51 + 49; |
128 geo_init(&g, 2, pos); | 135 geo_from_positions(&g, 2, pos); |
129 geo_mark_overlay(&g, 3, geos, &n_ov, overlays); | 136 geo_mark_overlay(&g, 3, geos, &n_ov, overlays); |
130 CU_ASSERT(n_ov == 1); | 137 CU_ASSERT(n_ov == 1); |
131 CU_ASSERT(overlays[0] == geos[2]); | 138 CU_ASSERT(overlays[0] == geos[2]); |
132 } | 139 } |
133 | 140 |
134 CU_pSuite get_geo_suite(void) { | 141 CU_pSuite get_geo_suite(void) { |
135 CU_pSuite suite; | 142 CU_pSuite suite; |
136 | 143 |
137 suite = CU_add_suite("Suite_geo", NULL, NULL); | 144 suite = CU_add_suite("Suite_geo", NULL, NULL); |
138 CU_ADD_TEST(suite, test_geo_init); | 145 CU_ADD_TEST(suite, test_geo_from_positions); |
139 CU_ADD_TEST(suite, test_geo_mark_overlay); | 146 CU_ADD_TEST(suite, test_geo_mark_overlay); |
140 | 147 |
141 return suite; | 148 return suite; |
142 } | 149 } |
143 | 150 |