rowcol.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef _ROWCOL_H
  2. #define _ROWCOL_H
  3. /* these defines work with modeling coordinates only */
  4. /* TODO: avoid integer overflow */
  5. /* view resolutions */
  6. #define VXRES(gs) (gs->x_mod * gs->xres)
  7. #define VYRES(gs) (gs->y_mod * gs->yres)
  8. /* number of viewres rows/cols */
  9. #define VROWS(gs) (int)((gs->rows -1)/gs->y_mod)
  10. #define VCOLS(gs) (int)((gs->cols -1)/gs->x_mod)
  11. /* data row & col to offset */
  12. #define DRC2OFF(gs, drow, dcol) (int)((dcol) + (drow) * gs->cols)
  13. /* ycoord/xcoord to data row/col */
  14. #define Y2DROW(gs,py) (int)((gs->yrange - (py))/gs->yres)
  15. #define X2DCOL(gs,px) (int)((px)/gs->xres)
  16. /* ycoord/xcoord to offset */
  17. #define XY2OFF(gs, px, py) (int)DRC2OFF(gs, Y2DROW(gs,py), X2DCOL(gs,px))
  18. /* ycoord/xcoord to viewres row/col */
  19. #define Y2VROW(gs,py) (int)((gs->yrange - (py))/(gs->yres * gs->y_mod))
  20. #define X2VCOL(gs,px) (int)((px)/(gs->xres * gs->x_mod))
  21. /* viewres row/col to data row/col */
  22. #define VROW2DROW(gs,vrow) (int)(gs->y_mod * (vrow))
  23. #define VCOL2DCOL(gs,vcol) (int)(gs->x_mod * (vcol))
  24. /* data row/col to ycoord/xcoord */
  25. #define DROW2Y(gs,drow) (gs->yrange - ((drow) * gs->yres))
  26. #define DCOL2X(gs,dcol) ((dcol) * gs->xres)
  27. /* viewres row/col to ycoord/xcoord */
  28. #define VROW2Y(gs,vrow) (gs->yrange - ((vrow) * gs->yres * gs->y_mod))
  29. #define VCOL2X(gs,vcol) ((vcol) * gs->xres * gs->x_mod)
  30. #endif /* _ROWCOL_H */