summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_map.c
diff options
context:
space:
mode:
authorChunEon Park <hermet@hermet.pe.kr>2012-11-13 05:34:47 +0000
committerChunEon Park <hermet@hermet.pe.kr>2012-11-13 05:34:47 +0000
commit9467a3169a302102c03153dab0785c6d0512d39e (patch)
tree6ae0615e46972a40f253432f5e94527e6c2e60fc /src/lib/evas/canvas/evas_map.c
parent2e6aaf35f150d43da3f61d504387e58085e1a3c7 (diff)
evas/map - simple refactoring.
SVN revision: 79197
Diffstat (limited to 'src/lib/evas/canvas/evas_map.c')
-rw-r--r--src/lib/evas/canvas/evas_map.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/src/lib/evas/canvas/evas_map.c b/src/lib/evas/canvas/evas_map.c
index 901cbd8..69f3817 100644
--- a/src/lib/evas/canvas/evas_map.c
+++ b/src/lib/evas/canvas/evas_map.c
@@ -220,34 +220,6 @@ _evas_map_util_points_populate(Evas_Map *m, const Evas_Coord x, const Evas_Coord
220} 220}
221 221
222Eina_Bool 222Eina_Bool
223_evas_map_inside_map_coords(const Evas_Map *m, Evas_Coord x, Evas_Coord y)
224{
225 int i = 0, j = m->count - 1;
226 double pt1_x, pt1_y, pt2_x, pt2_y, tmp_x;
227 Eina_Bool inside = EINA_FALSE;
228
229 //Check the point inside the map coords by using Jordan curve theorem.
230 for (i = 0; i < m->count; i++)
231 {
232 pt1_x = m->points[i].x;
233 pt1_y = m->points[i].y;
234 pt2_x = m->points[j].x;
235 pt2_y = m->points[j].y;
236
237 //Is the point inside the map on y axis?
238 if (((y >= pt1_y) && (y < pt2_y)) || ((y >= pt2_y) && (y < pt1_y)))
239 {
240 //Check the point is left side of the line segment.
241 tmp_x = (pt1_x + ((pt2_x - pt1_x) / (pt2_y - pt1_y)) *
242 ((double)y - pt1_y));
243 if ((double)x < tmp_x) inside = !inside;
244 }
245 j = i;
246 }
247 return inside;
248}
249
250Eina_Bool
251evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y, 223evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
252 Evas_Coord *mx, Evas_Coord *my, int grab) 224 Evas_Coord *mx, Evas_Coord *my, int grab)
253{ 225{
@@ -255,10 +227,9 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
255 return EINA_FALSE; 227 return EINA_FALSE;
256 MAGIC_CHECK_END(); 228 MAGIC_CHECK_END();
257 229
258 if (m->count < 4) return 0; 230 if (m->count < 4) return EINA_FALSE;
259 231 if ((!mx) && (!my))
260 if ((!grab) && (!mx) && (!my)) 232 return evas_map_inside_get(m, x, y);
261 return _evas_map_inside_map_coords(m, x, y);
262 233
263 int i, j, edges, edge[m->count][2]; 234 int i, j, edges, edge[m->count][2];
264 Eina_Bool douv = EINA_FALSE; 235 Eina_Bool douv = EINA_FALSE;
@@ -266,7 +237,6 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
266 double u[2] = { 0.0, 0.0 }; 237 double u[2] = { 0.0, 0.0 };
267 double v[2] = { 0.0, 0.0 }; 238 double v[2] = { 0.0, 0.0 };
268 239
269 if (m->count < 4) return 0;
270 // FIXME need to handle grab mode and extrapolte coords outside 240 // FIXME need to handle grab mode and extrapolte coords outside
271 // map 241 // map
272 if (grab) 242 if (grab)
@@ -283,7 +253,7 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
283 if (y <= ymin) y = ymin + 1; 253 if (y <= ymin) y = ymin + 1;
284 if (y >= ymax) y = ymax - 1; 254 if (y >= ymax) y = ymax - 1;
285 } 255 }
286 edges = 0; 256 edges = EINA_FALSE;
287 for (i = 0; i < m->count; i++) 257 for (i = 0; i < m->count; i++)
288 { 258 {
289 j = (i + 1) % m->count; 259 j = (i + 1) % m->count;
@@ -398,7 +368,29 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
398Eina_Bool 368Eina_Bool
399evas_map_inside_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y) 369evas_map_inside_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y)
400{ 370{
401 return evas_map_coords_get(m, x, y, NULL, NULL, 0); 371 int i = 0, j = m->count - 1;
372 double pt1_x, pt1_y, pt2_x, pt2_y, tmp_x;
373 Eina_Bool inside = EINA_FALSE;
374
375 //Check the point inside the map coords by using Jordan curve theorem.
376 for (i = 0; i < m->count; i++)
377 {
378 pt1_x = m->points[i].x;
379 pt1_y = m->points[i].y;
380 pt2_x = m->points[j].x;
381 pt2_y = m->points[j].y;
382
383 //Is the point inside the map on y axis?
384 if (((y >= pt1_y) && (y < pt2_y)) || ((y >= pt2_y) && (y < pt1_y)))
385 {
386 //Check the point is left side of the line segment.
387 tmp_x = (pt1_x + ((pt2_x - pt1_x) / (pt2_y - pt1_y)) *
388 ((double)y - pt1_y));
389 if ((double)x < tmp_x) inside = !inside;
390 }
391 j = i;
392 }
393 return inside;
402} 394}
403 395
404static Eina_Bool 396static Eina_Bool