wind_2_box.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. * \file lib/gis/wind_2_box.c
  3. *
  4. * \brief GIS Library - Window box functions.
  5. *
  6. * (C) 2001-2014 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author GRASS GIS Development Team
  12. *
  13. * \date 1999-2014
  14. */
  15. #include <grass/gis.h>
  16. /**
  17. * \brief Adjusts window to a rectangular box.
  18. *
  19. * Creates a new window <b>dst</b> from a window <b>src</b> which fits
  20. * into the rectangular box with dimensions <b>rows</b> by <b>cols</b>.
  21. *
  22. * \param[in] src source window
  23. * \param[in,out] dst destination window
  24. * \param[in] rows number of rows in box
  25. * \param[in] cols number of columns in box
  26. * \return
  27. */
  28. void G_adjust_window_to_box(const struct Cell_head *src,
  29. struct Cell_head *dst, int rows, int cols)
  30. {
  31. double ew, ns;
  32. *dst = *src;
  33. /* calculate the effective resolutions */
  34. ns = (src->ns_res * src->rows) / rows;
  35. ew = (src->ew_res * src->cols) / cols;
  36. /* set both resolutions equal to the larger */
  37. if (ns > ew)
  38. ew = ns;
  39. else
  40. ns = ew;
  41. dst->ns_res = ns;
  42. dst->ew_res = ew;
  43. /* compute rows and cols */
  44. dst->rows = (dst->north - dst->south) / dst->ns_res;
  45. dst->cols = (dst->east - dst->west) / dst->ew_res;
  46. }