Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] Re: (PR#3924) Bugfix for map/canvas coordination functions
Home

[Freeciv-Dev] Re: (PR#3924) Bugfix for map/canvas coordination functions

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#3924) Bugfix for map/canvas coordination functions
From: "a-l@xxxxxxx" <a-l@xxxxxxx>
Date: Sun, 6 Apr 2003 15:30:36 -0700
Reply-to: rt@xxxxxxxxxxxxxx

> a-l@xxxxxxx wrote:
> > If this is not formalized already, I would propose that the
> > following should be a defined property of the two functions
> > in question:
> > 
> > That this verification procedure should hold true:
> > {
> >   map_to_canvas_pos(&x, &y, tile_x1, tile_y1);
> > 
> >   x += NORMAL_TILE_WIDTH / 2;
> >   y += NORMAL_TILE_HEIGHT / 2;
> > 
> >   canvas_to_map_pos(&tile_x2, &tile_y2, x, y);
> > 
> >   assert(tile_x1 == tile_x2);
> >   assert(tile_y1 == tile_y2);
> > }
> > For all tiles at all times.
> 

On Sun, 6 Apr 2003 13:21:28 -0700
"rwetmore@xxxxxxxxxxxx" <rwetmore@xxxxxxxxxxxx> wrote:

> If you define the tile origin as the upper left corner, then I
> think you should make sure that any value from [0,NORMAL_TILEWIDTH)
> and [0,NORMAL_TILE_HEIGHT) can be added to the initial coordinate
> transformation and the result will still be true.
> 

Yes, let's define the tile origin as the upper left corner of the draw
bounding box. This is what map_to_canvas_pos() yields. I have verified
that the above is true for non-iso by singel pixel iteration.
Obviously it's not true for the diamond-shaped tiles; but the
definition of the center of a tile should hold, always. I added a
header comment.

> If you define the center of the tile as the tile origin the range
> is [-NORMAL_TILE_WIDTH/2,NORMAL_TILE_WIDTH - NORMAL_TILE_WIDTH/2).

That could be useful for my rectangle patch, but most other (drawing)
code want upper left of the drawing box, I'm sure. I can add half a
tile, because the tile center is particularly interesting when doing
canvas to tile coordination geometry. Iterating over every pixel
would be too slow; but iterating every (half tile) pixels starting
from a center makes it easy to see if a tile is sufficiently inside a
figure, regardless of the proportion
NORMAL_TILE_WIDTH / NORMAL_TILE_HEIGHT.

> > We must add half a tile because of PR#3800, the bounding
> > draw box thing. Ie nobody should "fix" PR#3800.
> 
> Fix PR#3800 by defining the tile origin precisely and making the
> transformation conform to the definition.


Arnstein


--- cvs-Apr-04/client/mapview_common.c  Mon Apr  7 00:01:35 2003
+++ comment/client/mapview_common.c     Mon Apr  7 00:09:22 2003
@@ -149,8 +149,23 @@
 
 /**************************************************************************
   Finds the pixel coordinates of a tile.  Beside setting the results
-  in canvas_x,canvas_y it returns whether the tile is inside the
-  visible map.
+  in canvas_x, canvas_y it returns whether the tile is inside the
+  visible map. The result represents the upper left pixel of the
+  bounding draw box, which is always rectangular. Depending on map
+  topology, this result may not always yield the same tile when sent
+  to the reverse function without adjustment.
+
+  The center of a tile is defined as:
+  {
+    map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y);
+    canvas_x += NORMAL_TILE_WIDTH / 2;
+    canvas_y += NORMAL_TILE_HEIGHT / 2;
+  }
+
+  This pixel is one position closer to the lower right, which may be
+  important to remember when doing some round-off operations. Other
+  parts of the code assert NORMAL_TILE_WIDTH and NORMAL_TILE_HEIGHT
+  to be even numbers.
 **************************************************************************/
 bool map_to_canvas_pos(int *canvas_x, int *canvas_y, int map_x, int map_y)
 {

[Prev in Thread] Current Thread [Next in Thread]