GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
rowcol.h
Go to the documentation of this file.
1 #ifndef _ROWCOL_H
2 #define _ROWCOL_H
3 
4 /* these defines work with modeling coordinates only */
5 
6 /* TODO: avoid integer overflow */
7 
8 /* view resolutions */
9 #define VXRES(gs) (gs->x_mod * gs->xres)
10 #define VYRES(gs) (gs->y_mod * gs->yres)
11 
12 /* number of viewres rows/cols */
13 #define VROWS(gs) (int)((gs->rows -1)/gs->y_mod)
14 #define VCOLS(gs) (int)((gs->cols -1)/gs->x_mod)
15 
16 /* data row & col to offset */
17 #define DRC2OFF(gs, drow, dcol) (int)((dcol) + (drow) * gs->cols)
18 
19 /* ycoord/xcoord to data row/col */
20 #define Y2DROW(gs,py) (int)((gs->yrange - (py))/gs->yres)
21 #define X2DCOL(gs,px) (int)((px)/gs->xres)
22 
23 /* ycoord/xcoord to offset */
24 #define XY2OFF(gs, px, py) (int)DRC2OFF(gs, Y2DROW(gs,py), X2DCOL(gs,px))
25 
26 /* ycoord/xcoord to viewres row/col */
27 #define Y2VROW(gs,py) (int)((gs->yrange - (py))/(gs->yres * gs->y_mod))
28 #define X2VCOL(gs,px) (int)((px)/(gs->xres * gs->x_mod))
29 
30 /* viewres row/col to data row/col */
31 #define VROW2DROW(gs,vrow) (int)(gs->y_mod * (vrow))
32 #define VCOL2DCOL(gs,vcol) (int)(gs->x_mod * (vcol))
33 
34 /* data row/col to ycoord/xcoord */
35 #define DROW2Y(gs,drow) (gs->yrange - ((drow) * gs->yres))
36 #define DCOL2X(gs,dcol) ((dcol) * gs->xres)
37 
38 /* viewres row/col to ycoord/xcoord */
39 #define VROW2Y(gs,vrow) (gs->yrange - ((vrow) * gs->yres * gs->y_mod))
40 #define VCOL2X(gs,vcol) ((vcol) * gs->xres * gs->x_mod)
41 
42 #endif /* _ROWCOL_H */