evas_map: add calibrating coordinates when origin is changed. 65/295765/2 accepted/tizen/unified/20230719.170100 accepted/tizen/unified/dev/20230726.120038
authorHosang Kim <hosang12.kim@samsung.com>
Thu, 13 Jul 2023 09:28:24 +0000 (18:28 +0900)
committerkim hosang <hosang12.kim@samsung.com>
Tue, 18 Jul 2023 05:05:34 +0000 (05:05 +0000)
Change-Id: I632aa74b4ccb1fad32159643b865f197b12d9bc2

src/lib/evas/canvas/evas_map.c

index 973d10f..350627f 100644 (file)
@@ -267,11 +267,12 @@ evas_map_coords_get(const Evas_Map *m, double x, double y,
    // FIXME: need to handle grab mode and extrapolate coords outside map
    if (grab && !inside) return EINA_FALSE;
 
-   int i, j, edges, edge[m->count][2];
+   int i, j, edges, edgesx, edge[m->count][2], edgex[m->count][2];
    Eina_Bool douv = EINA_FALSE;
    double xe[2];
    double u[2] = { 0.0, 0.0 };
    double v[2] = { 0.0, 0.0 };
+   double xc = 0.0, yc = 0.0;
 
 /*
    if (grab)
@@ -290,6 +291,7 @@ evas_map_coords_get(const Evas_Map *m, double x, double y,
      }
 */
    edges = EINA_FALSE;
+   edgesx = EINA_FALSE;
    for (i = 0; i < m->count; i++)
      {
         j = (i + 1) % m->count;
@@ -305,7 +307,25 @@ evas_map_coords_get(const Evas_Map *m, double x, double y,
              edge[edges][1] = i;
              edges++;
           }
+        if ((m->points[i].x <= x) && (m->points[j].x > x))
+          {
+             edgex[edgesx][0] = i;
+             edgex[edgesx][1] = j;
+             edgesx++;
+          }
+        else if ((m->points[j].x <= x) && (m->points[i].x > x))
+          {
+             edgex[edgesx][0] = j;
+             edgex[edgesx][1] = i;
+             edgesx++;
+          }
      }
+   if (edges > 1) {
+     if (edge[0][1] < edge[0][0]) xc = -1.0;
+   }
+   if (edgesx > 1) {
+     if (edgex[0][1] < edgex[0][0]) yc = -1.0;
+   }
    if ((mx) || (my)) douv = EINA_TRUE;
    for (i = 0; i < (edges - 1); i+= 2)
      {
@@ -376,11 +396,11 @@ evas_map_coords_get(const Evas_Map *m, double x, double y,
              if (douv)
                {
                   if (mx)
-                    *mx = u[0] + (((x - xe[0]) * (u[1] - u[0])) /
-                                  (xe[1] - xe[0]));
+                    *mx = u[0] + xc + (((x - xe[0]) * (u[1] - u[0])) /
+                                       (xe[1] - xe[0]));
                   if (my)
-                    *my = v[0] + (((x - xe[0]) * (v[1] - v[0])) /
-                                  (xe[1] - xe[0]));
+                    *my = v[0] + yc + (((x - xe[0]) * (v[1] - v[0])) /
+                                       (xe[1] - xe[0]));
                }
              return EINA_TRUE;
           }