summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_map.c
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-13 04:08:16 +0000
committerChunEon Park <hermet@hermet.pe.kr>2012-11-13 04:08:16 +0000
commit2e6aaf35f150d43da3f61d504387e58085e1a3c7 (patch)
tree072dc706d6a7dc549e4757be28c0e8e5f0f9c54a /src/lib/evas/canvas/evas_map.c
parentc3f30cb456de26a75793e4dbdde3e31016cf9824 (diff)
evas - return quickly if you got the result.
Signed-Off-By: Leandro Dorileo <dorileo@profusion.mobi> SVN revision: 79196
Diffstat (limited to 'src/lib/evas/canvas/evas_map.c')
-rw-r--r--src/lib/evas/canvas/evas_map.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/lib/evas/canvas/evas_map.c b/src/lib/evas/canvas/evas_map.c
index 3338d37..901cbd8 100644
--- a/src/lib/evas/canvas/evas_map.c
+++ b/src/lib/evas/canvas/evas_map.c
@@ -220,6 +220,34 @@ _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
223evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y, 251evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
224 Evas_Coord *mx, Evas_Coord *my, int grab) 252 Evas_Coord *mx, Evas_Coord *my, int grab)
225{ 253{
@@ -227,7 +255,13 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
227 return EINA_FALSE; 255 return EINA_FALSE;
228 MAGIC_CHECK_END(); 256 MAGIC_CHECK_END();
229 257
230 int i, j, edges, edge[m->count][2], douv; 258 if (m->count < 4) return 0;
259
260 if ((!grab) && (!mx) && (!my))
261 return _evas_map_inside_map_coords(m, x, y);
262
263 int i, j, edges, edge[m->count][2];
264 Eina_Bool douv = EINA_FALSE;
231 Evas_Coord xe[2]; 265 Evas_Coord xe[2];
232 double u[2] = { 0.0, 0.0 }; 266 double u[2] = { 0.0, 0.0 };
233 double v[2] = { 0.0, 0.0 }; 267 double v[2] = { 0.0, 0.0 };
@@ -266,8 +300,7 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
266 edges++; 300 edges++;
267 } 301 }
268 } 302 }
269 douv = 0; 303 if ((mx) || (my)) douv = EINA_TRUE;
270 if ((mx) || (my)) douv = 1;
271 for (i = 0; i < (edges - 1); i+= 2) 304 for (i = 0; i < (edges - 1); i+= 2)
272 { 305 {
273 Evas_Coord yp, yd; 306 Evas_Coord yp, yd;
@@ -339,7 +372,7 @@ evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y,
339 if (mx) 372 if (mx)
340 *mx = u[0] + (((x - xe[0]) * (u[1] - u[0])) / 373 *mx = u[0] + (((x - xe[0]) * (u[1] - u[0])) /
341 (xe[1] - xe[0])); 374 (xe[1] - xe[0]));
342 if (my) 375 if (my)
343 *my = v[0] + (((x - xe[0]) * (v[1] - v[0])) / 376 *my = v[0] + (((x - xe[0]) * (v[1] - v[0])) /
344 (xe[1] - xe[0])); 377 (xe[1] - xe[0]));
345 } 378 }