comparison src/geo.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
16 return 0; 16 return 0;
17 } 17 }
18 return 1; 18 return 1;
19 } 19 }
20 20
21 static int _is_overlay(geo_t *r1, geo_t *r2) { 21 static int _is_overlay(area_t *r1, area_t *r2) {
22 if(!is_scale_overlay(r1->x, r1->w, r2->x, r2->w)) 22 if(!is_scale_overlay(r1->x, r1->w, r2->x, r2->w))
23 return 0; 23 return 0;
24 if(!is_scale_overlay(r1->y, r1->h, r2->y, r2->h)) 24 if(!is_scale_overlay(r1->y, r1->h, r2->y, r2->h))
25 return 0; 25 return 0;
26 26
27 return 1; 27 return 1;
28 } 28 }
29 29
30 int is_overlay(geo_t *r1, geo_t *r2) { 30 int is_overlay(area_t *r1, area_t *r2) {
31 return _is_overlay(r1, r2); 31 return _is_overlay(r1, r2);
32 } 32 }
33 33
34 void geo_init(geo_t *g, int n_pos, co_aix pos[][2]) { 34 void geo_init(geo_t *g, int n_pos, co_aix pos[][2]) {
35 co_aix min_x, max_x; 35 co_aix min_x, max_x;
49 if(y < min_y) 49 if(y < min_y)
50 min_y = y; 50 min_y = y;
51 else if(y > max_y) 51 else if(y > max_y)
52 max_y = y; 52 max_y = y;
53 } 53 }
54 g->x = min_x; 54
55 g->w = max_x - min_x; 55 g->cur_area = g->areas;
56 g->y = min_y; 56 g->last_area = g->areas + 1;
57 g->h = max_y - min_y; 57
58 g->cur_area->x = min_x;
59 g->cur_area->w = max_x - min_x;
60 g->cur_area->y = min_y;
61 g->cur_area->h = max_y - min_y;
58 } 62 }
59 63
60 void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, 64 void geo_mark_overlay(geo_t *g, int n_others, geo_t **others,
61 int *n_overlays, geo_t **overlays) { 65 int *n_overlays, geo_t **overlays) {
62 int i, ov_idx; 66 int i, ov_idx;
63 67
64 ov_idx = 0; 68 ov_idx = 0;
65 for(i = 0; i < n_others; i++) { 69 for(i = 0; i < n_others; i++) {
66 if(_is_overlay(g, others[i])) 70 if(_is_overlay(g->cur_area, others[i]->cur_area))
67 overlays[ov_idx++] = others[i]; 71 overlays[ov_idx++] = others[i];
68 } 72 }
69 *n_overlays = ov_idx; 73 *n_overlays = ov_idx;
70 } 74 }
71 75
79 {33, 25}, {49, 12}, 83 {33, 25}, {49, 12},
80 {14, 28}, {39, 56}}; 84 {14, 28}, {39, 56}};
81 geo_t g; 85 geo_t g;
82 86
83 geo_init(&g, 4, data); 87 geo_init(&g, 4, data);
84 CU_ASSERT(g.x == 14); 88 CU_ASSERT(g.cur_area->x == 14);
85 CU_ASSERT(g.w == 35); 89 CU_ASSERT(g.cur_area->w == 35);
86 CU_ASSERT(g.y == 12); 90 CU_ASSERT(g.cur_area->y == 12);
87 CU_ASSERT(g.h == 44); 91 CU_ASSERT(g.cur_area->h == 44);
88 } 92 }
89 93
90 void test_geo_mark_overlay(void) { 94 void test_geo_mark_overlay(void) {
91 geo_t _geos[3], *geos[3], *overlays[3]; 95 geo_t _geos[3], *geos[3], *overlays[3];
92 geo_t g; 96 geo_t g;
97 co_aix pos[2][2];
93 int i, n_ov; 98 int i, n_ov;
94 99
95 for(i = 0; i < 3; i++) { 100 for(i = 0; i < 3; i++) {
96 _geos[i].x = i * 50; 101 pos[0][0] = i * 50;
97 _geos[i].y = i * 50; 102 pos[0][1] = i * 50;
98 _geos[i].w = 55; 103 pos[1][0] = i * 50 + 55;
99 _geos[i].h = 66; 104 pos[1][1] = i * 50 + 66;
105 geo_init(_geos + i, 2, pos);
100 geos[i] = _geos + i; 106 geos[i] = _geos + i;
101 } 107 }
102 g.x = 88; 108 pos[0][0] = 88;
103 g.y = 79; 109 pos[0][1] = 79;
104 g.w = 70; 110 pos[1][0] = 88 + 70;
105 g.h = 70; 111 pos[1][1] = 79 + 70;
112 geo_init(&g, 2, pos);
106 113
107 /* overlay with geos[1] and geos[2] */ 114 /* overlay with geos[1] and geos[2] */
108 geo_mark_overlay(&g, 3, geos, &n_ov, overlays); 115 geo_mark_overlay(&g, 3, geos, &n_ov, overlays);
109 CU_ASSERT(n_ov == 2); 116 CU_ASSERT(n_ov == 2);
110 CU_ASSERT(overlays[0] == geos[1]); 117 CU_ASSERT(overlays[0] == geos[1]);
111 CU_ASSERT(overlays[1] == geos[2]); 118 CU_ASSERT(overlays[1] == geos[2]);
112 119
113 /* right side of geos[1], and up side of geos[2] */ 120 /* right side of geos[1], and up side of geos[2] */
114 g.x = 105; 121 pos[0][0] = 105;
115 g.y = 50; 122 pos[0][1] = 50;
116 g.w = 50; 123 pos[1][0] = 105 + 50;
117 g.h = 51; 124 pos[1][1] = 50 + 51;
125 geo_init(&g, 2, pos);
118 geo_mark_overlay(&g, 3, geos, &n_ov, overlays); 126 geo_mark_overlay(&g, 3, geos, &n_ov, overlays);
119 CU_ASSERT(n_ov == 1); 127 CU_ASSERT(n_ov == 1);
120 CU_ASSERT(overlays[0] == geos[2]); 128 CU_ASSERT(overlays[0] == geos[2]);
121 } 129 }
122 130