Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4681) cleanup to map_to_canvas_pos
Home

[Freeciv-Dev] (PR#4681) cleanup to map_to_canvas_pos

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4681) cleanup to map_to_canvas_pos
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Jul 2003 00:12:37 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch cleans up map_to_canvas_pos in two ways:

- Wrapping is done in a better way.  This (along with PR#4679) should 
fix PR#81.  Previously wrapping was buggy in non-iso view (see PR#81).

- Secondly the return value is more correct.  It may not make any 
difference now, but it is simpler and will continue to work if offsets 
are introduced in the future.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.53
diff -u -r1.53 mapview_common.c
--- client/mapview_common.c     2003/07/23 13:46:01     1.53
+++ client/mapview_common.c     2003/07/25 07:10:23
@@ -178,23 +178,23 @@
 **************************************************************************/
 bool map_to_canvas_pos(int *canvas_x, int *canvas_y, int map_x, int map_y)
 {
+  /*
+   * First we wrap the coordinates to hopefully be within the the
+   * GUI window.  This isn't perfect; notice that when the mapview
+   * approaches the size of the map some tiles won't be shown at
+   * all in iso-view.
+   */
+  map_x = map_adjust_x(map_x);
+  if (map_x < mapview_canvas.map_x0) {
+    map_x += map.xsize;
+  }
+
   if (is_isometric) {
     /* For a simpler example of this math, see
        city_pos_to_canvas_pos(). */
     int iso_x, iso_y;
 
     /*
-     * First we wrap the coordinates to hopefully be within the the
-     * GUI window.  This isn't perfect; notice that when the mapview
-     * approaches the size of the map some tiles won't be shown at
-     * all.
-     */
-    map_x %= map.xsize;
-    if (map_x < mapview_canvas.map_x0) {
-      map_x += map.xsize;
-    }
-
-    /*
      * Next we convert the flat GUI coordinates to isometric GUI
      * coordinates.  We'll make tile (x0, y0) be the origin, and
      * transform like this:
@@ -220,35 +220,22 @@
      */
     *canvas_x = (iso_x - 1) * NORMAL_TILE_WIDTH / 2;
     *canvas_y = iso_y * NORMAL_TILE_HEIGHT / 2;
-
-    /*
-     * Finally we clip; checking to see if _any part_ of the tile is
-     * visible on the canvas.
-     */
-    return (*canvas_x > -NORMAL_TILE_WIDTH)
-       && *canvas_x < (mapview_canvas.width + NORMAL_TILE_WIDTH / 2)
-       && (*canvas_y > -NORMAL_TILE_HEIGHT)
-       && *canvas_y < mapview_canvas.height;
   } else {                     /* is_isometric */
-    if (mapview_canvas.map_x0 + mapview_canvas.tile_width <= map.xsize) {
-      *canvas_x = map_x - mapview_canvas.map_x0;
-    } else if (map_x >= mapview_canvas.map_x0) {
-      *canvas_x = map_x - mapview_canvas.map_x0;
-    } else if (map_x < map_adjust_x(mapview_canvas.map_x0
-                                   + mapview_canvas.tile_width)) {
-      *canvas_x = map_x + map.xsize - mapview_canvas.map_x0;
-    } else {
-      *canvas_x = map_x - mapview_canvas.map_x0;
-    }
-
+    *canvas_x = map_x - mapview_canvas.map_x0;
     *canvas_y = map_y - mapview_canvas.map_y0;
 
     *canvas_x *= NORMAL_TILE_WIDTH;
     *canvas_y *= NORMAL_TILE_HEIGHT;
-
-    return *canvas_x >= 0 && *canvas_x < mapview_canvas.width
-        && *canvas_y >= 0 && *canvas_y < mapview_canvas.height;
   }
+
+  /*
+   * Finally we clip; checking to see if _any part_ of the tile is
+   * visible on the canvas.
+   */
+  return (*canvas_x > -NORMAL_TILE_WIDTH
+         && *canvas_x < mapview_canvas.width
+         && *canvas_y > -NORMAL_TILE_HEIGHT
+         && *canvas_y < mapview_canvas.height);
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4681) cleanup to map_to_canvas_pos, Jason Short <=