window_map.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*!
  2. * \file window_map.c
  3. *
  4. * \brief GIS Library - Window mapping functions.
  5. *
  6. * (C) 2001-2009 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 Original author CERL
  12. */
  13. #include <grass/gis.h>
  14. #include "G.h"
  15. /*!
  16. * \brief Adjust east longitude.
  17. *
  18. * This routine returns an equivalent <i>east</i> that is
  19. * larger, but no more than 360 larger than the <i>west</i>
  20. * coordinate.
  21. * <b>Note:</b> This routine should be used only with
  22. * latitude-longitude coordinates.
  23. *
  24. * \param east east coordinate
  25. * \param west west coordinate
  26. *
  27. * \return east coordinate
  28. */
  29. double G_adjust_east_longitude(double east, double west)
  30. {
  31. while (east > west + 360.0)
  32. east -= 360.0;
  33. while (east <= west)
  34. east += 360.0;
  35. return east;
  36. }
  37. /*!
  38. * \brief Returns east larger than west.
  39. *
  40. * If the region projection is <tt>PROJECTION_LL</tt>, then this routine
  41. * returns an equivalent <i>east</i> that is larger, but no more than
  42. * 360 degrees larger, than the coordinate for the western edge of the
  43. * region. Otherwise no adjustment is made and the original
  44. * <i>east</i> is returned.
  45. *
  46. * \param east east coordinate
  47. * \param window pointer to Cell_head
  48. *
  49. * \return east coordinate
  50. */
  51. double G_adjust_easting(double east, const struct Cell_head *window)
  52. {
  53. if (window->proj == PROJECTION_LL) {
  54. east = G_adjust_east_longitude(east, window->west);
  55. if (east > window->east && east == window->west + 360)
  56. east = window->west;
  57. }
  58. return east;
  59. }
  60. /*!
  61. * \brief Initialize window.
  62. *
  63. */
  64. void G__init_window(void)
  65. {
  66. if (G_is_initialized(&G__.window_set))
  67. return;
  68. G_get_window(&G__.window);
  69. G_initialize_done(&G__.window_set);
  70. }