[GRASS5] display windows off by one?

Hamish hamish_nospam at yahoo.com
Mon Feb 9 02:27:50 EST 2004


Hi folks,


I was having a look at why d.frame's boxes don't line up properly..

If you do:

d.erase color=black  
d.frame -c frame=one at=0,50,0,50
d.erase color=blue
d.frame -c frame=two at=50,100,50,100
d.erase color=red
d.frame -s frame=one
xmag   # zoom in on the very middle of the window

you can see that the frames are drawn one pixel to wide and tall.


The following patch more or less fixes that, but ...
===============================================
diff -u -r1.1.1.1 window.c
--- src/libes/display/window.c  29 Dec 1999 15:10:26 -0000      1.1.1.1
+++ src/libes/display/window.c  9 Feb 2004 06:44:04 -0000
@@ -174,11 +174,11 @@
                return(stat) ;
 
        R_standard_color(color) ;
-       R_move_abs(l-1, b+1) ;
+       R_move_abs(l-1, b) ;
        R_cont_abs(l-1, t-1) ;
-       R_cont_abs(r+1, t-1) ;
-       R_cont_abs(r+1, b+1) ;
-       R_cont_abs(l-1, b+1) ;
+       R_cont_abs(r, t-1) ;
+       R_cont_abs(r, b) ;
+       R_cont_abs(l-1, b) ;
        R_flush() ;
 
        return(0) ;
===============================================


.. it occurs to be this may only be treating the symptom.

If you add this command to both frames above,
  d.grid -g size=1000

and run xmag again, you can see that it draws the right and bottom sides 
of the grid's border outside of the normal window. 
(try d.grid with the PNG driver to highlight the problem)


I had a go at fixing src/display/d.grid/cmd/plotborder.c, something like:

row_dist = fabs(D_d_to_u_row(1) - D_d_to_u_row(0)); /* prob. no fabs */
col_dist = fabs(D_d_to_u_col(1) - D_d_to_u_col(0));
window.south = window.south + row_dist;
window.east  = window.east  - col_dist;

to shrink the right & bottom by one pixel width before plotting, but again,
it seems like a band-aid on a bigger problem.

Different people treating the top-left pixel as [0,0] & others as [1,1]?

...

also,
Section 16.5 (Coordinate Transformation Routines) of the 5.0 Programmer's
Manual states:

Coordinate system Origin 
Array upperleft           (NW) 
Display screen upper left (NW) 
Earth lower left          (SW)

(but no mention of origin being [0,0] or [1,1] .. I guess trial and error
would tell)

Does this mean d.frame at=% of window should treat 0%,0% as top left?
Right now some modules treat '% of display frame' as bottom left, some
as top left. It would be nice to make the modules consistent before the 
next major release..


any suggestions?



Hamish




More information about the grass-dev mailing list