Author: cazfi
Date: Wed Oct 28 21:54:33 2015
New Revision: 30296

URL: http://svn.gna.org/viewcvs/freeciv?rev=30296&view=rev
Log:
Made gui_to_map() to use floats internally.

See patch #6447

Modified:
    trunk/client/mapview_common.c
    trunk/client/mapview_common.h

Modified: trunk/client/mapview_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/mapview_common.c?rev=30296&r1=30295&r2=30296&view=diff
==============================================================================
--- trunk/client/mapview_common.c       (original)
+++ trunk/client/mapview_common.c       Wed Oct 28 21:54:33 2015
@@ -77,7 +77,7 @@
 struct tile *center_tile = NULL;
 
 static void base_canvas_to_map_pos(int *map_x, int *map_y,
-                                  int canvas_x, int canvas_y);
+                                   float canvas_x, float canvas_y);
 
 enum update_type {
   /* Masks */
@@ -236,21 +236,22 @@
   the same value you started with.
 ****************************************************************************/
 static void gui_to_map_pos(const struct tileset *t,
-                          int *map_x, int *map_y, int gui_x, int gui_y)
-{
-  const int W = tileset_tile_width(t) * map_zoom, H = tileset_tile_height(t) * 
map_zoom;
-  const int HH = tileset_hex_height(t) * map_zoom, HW = tileset_hex_width(t) * 
map_zoom;
+                           int *map_x, int *map_y, float gui_x, float gui_y)
+{
+  const float W = tileset_tile_width(t) * map_zoom, H = tileset_tile_height(t) 
* map_zoom;
+  const float HH = tileset_hex_height(t) * map_zoom, HW = tileset_hex_width(t) 
* map_zoom;
 
   if (HH > 0 || HW > 0) {
     /* To handle hexagonal cases we have to revert to a less elegant method
      * of calculation. */
-    int x, y, dx, dy;
+    float x, y;
+    int dx, dy;
     int xmult, ymult, mod, compar;
 
     fc_assert(tileset_is_isometric(t));
 
-    x = DIVIDE(gui_x, W);
-    y = DIVIDE(gui_y, H);
+    x = gui_x / W;
+    y = gui_y / H;
     dx = gui_x - x * W;
     dy = gui_y - y * H;
     fc_assert(dx >= 0 && dx < W);
@@ -304,13 +305,13 @@
      * For another example of this math, see canvas_to_city_pos().
      */
     gui_x -= W / 2;
-    *map_x = DIVIDE(gui_x * H + gui_y * W, W * H);
-    *map_y = DIVIDE(gui_y * W - gui_x * H, W * H);
+    *map_x = DIVIDE((int)(gui_x * H + gui_y * W), (int)(W * H));
+    *map_y = DIVIDE((int)(gui_y * W - gui_x * H), (int)(W * H));
   } else {                     /* tileset_is_isometric(t) */
     /* We use DIVIDE so that we will get the correct result even
      * for negative coordinates. */
-    *map_x = DIVIDE(gui_x, W);
-    *map_y = DIVIDE(gui_y, H);
+    *map_x = DIVIDE((int)gui_x, (int)W);
+    *map_y = DIVIDE((int)gui_y, (int)H);
   }
 }
 
@@ -381,18 +382,18 @@
   resulting position is unwrapped and may be unreal.
 ****************************************************************************/
 static void base_canvas_to_map_pos(int *map_x, int *map_y,
-                                  int canvas_x, int canvas_y)
+                                  float canvas_x, float canvas_y)
 {
   gui_to_map_pos(tileset, map_x, map_y,
-                canvas_x + mapview.gui_x0,
-                canvas_y + mapview.gui_y0);
+                 canvas_x + mapview.gui_x0,
+                 canvas_y + mapview.gui_y0);
 }
 
 /**************************************************************************
   Finds the tile corresponding to pixel coordinates.  Returns that tile,
   or NULL if the position is off the map.
 **************************************************************************/
-struct tile *canvas_pos_to_tile(int canvas_x, int canvas_y)
+struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y)
 {
   int map_x, map_y;
 
@@ -408,7 +409,7 @@
   Finds the tile corresponding to pixel coordinates.  Returns that tile,
   or the one nearest is the position is off the map.  Will never return NULL.
 **************************************************************************/
-struct tile *canvas_pos_to_nearest_tile(int canvas_x, int canvas_y)
+struct tile *canvas_pos_to_nearest_tile(float canvas_x, float canvas_y)
 {
   int map_x, map_y;
 

Modified: trunk/client/mapview_common.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/mapview_common.h?rev=30296&r1=30295&r2=30296&view=diff
==============================================================================
--- trunk/client/mapview_common.h       (original)
+++ trunk/client/mapview_common.h       Wed Oct 28 21:54:33 2015
@@ -249,8 +249,8 @@
 void map_to_gui_vector(const struct tileset *t, float zoom,
                       float *gui_dx, float *gui_dy, int map_dx, int map_dy);
 bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, struct tile *ptile);
-struct tile *canvas_pos_to_tile(int canvas_x, int canvas_y);
-struct tile *canvas_pos_to_nearest_tile(int canvas_x, int canvas_y);
+struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y);
+struct tile *canvas_pos_to_nearest_tile(float canvas_x, float canvas_y);
 
 void get_mapview_scroll_window(float *xmin, float *ymin,
                                float *xmax, float *ymax,


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to