]> Pileus Git - grits/blob - src/grits-util.h
Add motion threshold when clicking objects
[grits] / src / grits-util.h
1 /*
2  * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GRITS_UTIL_H__
19 #define __GRITS_UTIL_H__
20
21 #include <glib.h>
22
23 /**
24  * EARTH_R:
25  *
26  * Radius of the earth
27  */
28 #define EARTH_R (6371000)
29
30 /**
31  * EARTH_C:
32  *
33  * Circumference of the earth at the equator
34  */
35 #define EARTH_C (2*G_PI*EARTH_R)
36
37 /**
38  * NORTH:
39  *
40  * Latitude at the north poll
41  */
42 #define NORTH  90
43
44 /**
45  * SOUTH:
46  *
47  * Latitude at the south poll
48  */
49 #define SOUTH -90
50
51 /**
52  * EAST:
53  *
54  * Eastern most longitude
55  */
56 #define EAST  180
57
58 /**
59  * WEST:
60  *
61  * Western most longitude
62  */
63 #define WEST -180
64
65 /***************
66  * Conversions *
67  ***************/
68 /**
69  * azim2lon:
70  * @azim: the azimuth in radians
71  *
72  * Convert azimuth to longitude
73  *
74  * Returns: the longitude 
75  */
76 #define azim2lon(azim) ((azim)*180/G_PI)
77
78 /**
79  * lon2azim:
80  * @lon: the longitude
81  *
82  * Convert longitude to azimuth 
83  *
84  * Returns: the azimuth in radians
85  */
86 #define lon2azim(lon)  ((lon)*G_PI/180)
87
88 /**
89  * incl2lat:
90  * @incl: the inclination in radians
91  *
92  * Convert inclination to latitude
93  *
94  * Returns: the latitude
95  */
96 #define incl2lat(incl) (90-(incl)*180/G_PI)
97
98 /**
99  * lat2incl:
100  * @lat: the latitude
101  *
102  * Convert latitude to inclination
103  *
104  * Returns: the inclination in radians
105  */
106 #define lat2incl(lat)  ((90-(lat))*G_PI/180)
107
108 /**
109  * rad2elev:
110  * @rad: the radius in meters
111  *
112  * Convert radius to elevation
113  *
114  * Returns: the elevation in meters above the earth surface
115  */
116 #define rad2elev(rad)  ((rad)-EARTH_R)
117
118 /**
119  * elev2rad:
120  * @elev: the elevation in meters above the earth surface
121  *
122  * Convert elevation to radius
123  *
124  * Returns: the radius in meters
125  */
126 #define elev2rad(elev) ((elev)+EARTH_R)
127
128 /**
129  * deg2rad:
130  * @deg: the angle in degrees
131  *
132  * Convert degrees to radians
133  *
134  * Returns: the angle in radians
135  */
136 #define deg2rad(deg) (((deg)*G_PI)/180.0)
137
138 /**
139  * rad2deg:
140  * @rad: the angle in radians
141  *
142  * Convert radians to degrees
143  *
144  * Returns: the angle in degrees
145  */
146 #define rad2deg(rad) (((rad)*180.0)/G_PI)
147
148
149 /*************
150  * Datatypes *
151  *************/
152
153 /* GritsPoint */
154 typedef struct _GritsPoint GritsPoint;
155 struct _GritsPoint {
156         gdouble lat, lon, elev;
157 };
158
159 void grits_point_set_lle(GritsPoint *point,
160                 gdouble lat, gdouble lon, gdouble elev);
161
162 /* GritsPoints */
163 typedef gdouble (*GritsPoints)[3];
164
165 /* GritsBounds */
166 typedef struct _GritsBounds GritsBounds;
167 struct _GritsBounds {
168         gdouble n, s, e, w;
169 };
170
171 void grits_bounds_set_bounds(GritsBounds *bounds,
172                 gdouble n, gdouble s, gdouble e, gdouble w);
173
174
175 /********
176  * Misc *
177  ********/
178 /**
179  * FOV_DIST:
180  *
181  * Used by GritsOpenGL to set up the drawing window
182  */
183 #define FOV_DIST   (1039.23)
184
185 /**
186  * MPPX:
187  * @dist: the distance between the eye and the point in question
188  *
189  * Get the resolution that a point would be drawn at on the screen
190  *
191  * Returns: the resolution in meters per pixel
192  */
193 #define MPPX(dist) (dist/FOV_DIST)
194
195 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
196                 gdouble *x, gdouble *y, gdouble *z);
197
198 void xyz2lle(gdouble x, gdouble y, gdouble z,
199                 gdouble *lat, gdouble *lon, gdouble *elev);
200
201 void xyz2ll(gdouble x, gdouble y, gdouble z,
202                 gdouble *lat, gdouble *lon);
203
204 gdouble ll2m(gdouble lon_dist, gdouble lat);
205
206 gdouble distd(gdouble *a, gdouble *b);
207
208 void crossd(gdouble *a, gdouble *b, gdouble *out);
209
210 void crossd3(gdouble *a, gdouble *b, gdouble *c, gdouble *out);
211
212 gdouble lengthd(gdouble *a);
213
214 void normd(gdouble *a);
215
216 gdouble lon_avg(gdouble a, gdouble b);
217
218 GritsPoints *parse_points(const gchar *string,
219                 const gchar *group_sep, const gchar *point_sep, const gchar *coord_sep,
220                 GritsBounds *bounds, GritsPoint *center);
221
222 void free_points(GritsPoints *points);
223
224 #endif