window_map.c 1.8 KB

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