window_map.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 at least as
  14. large as 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. double shift;
  24. shift = 0;
  25. while (east + shift < west)
  26. shift += 360.0;
  27. return east + shift;
  28. }
  29. /*!
  30. \brief Returns east not smaller than west.
  31. If the region projection is <tt>PROJECTION_LL</tt>, then this
  32. routine returns an equivalent <i>east</i> that is not smaller than
  33. the coordinate for the western edge of the region and, if possible,
  34. smaller than the coordinate for the eastern edge of the region.
  35. Otherwise no adjustment is made and the original <i>east</i> is
  36. returned.
  37. \param east east coordinate
  38. \param window pointer to Cell_head
  39. \return east coordinate
  40. */
  41. double G_adjust_easting(double east, const struct Cell_head *window)
  42. {
  43. double shift;
  44. shift = 0;
  45. if (window->proj == PROJECTION_LL) {
  46. while (east + shift >= window->east)
  47. shift -= 360.0;
  48. while (east + shift < window->west)
  49. shift += 360.0;
  50. }
  51. return east + shift;
  52. }
  53. /*!
  54. \brief Initialize window (region).
  55. */
  56. void G__init_window(void)
  57. {
  58. if (G_is_initialized(&G__.window_set))
  59. return;
  60. G_get_window(&G__.window);
  61. G_initialize_done(&G__.window_set);
  62. }