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