Contents of /trunk/src/pos.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations)
Sun Jan 18 19:43:20 2009 UTC (15 years, 3 months ago) by harbaum
File MIME type: text/plain
File size: 2631 byte(s)
Option to use float math instead of double
1 /*
2 * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3 *
4 * This file is part of OSM2Go.
5 *
6 * OSM2Go is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OSM2Go is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef POS_H
21 #define POS_H
22
23 #include <math.h>
24
25 #ifdef USE_FLOAT
26 /* use float instead of double on small machines */
27 typedef float pos_float_t;
28 #else
29 typedef double pos_float_t;
30 #endif
31
32 #ifndef NAN
33 #define NAN (0.0/0.0)
34 #endif
35
36 /* equatorial radius in meters */
37 #define POS_EQ_RADIUS (6378137.0)
38 #define KMPMIL (1.609344)
39 #define KM2MIL(a) ((a)/KMPMIL)
40 #define MIL2KM(a) ((a)*KMPMIL)
41
42 #define DEG2RAD(a) ((a) * M_PI / 180.0)
43 #define RAD2DEG(a) ((a) * 180.0 / M_PI)
44
45 /* global position */
46 typedef struct pos {
47 pos_float_t lat, lon;
48 } pos_t;
49
50 /* local position */
51 typedef struct lpos {
52 gint x, y;
53 } lpos_t;
54
55 struct bounds_s;
56 void pos2lpos(struct bounds_s *bounds, pos_t *pos, lpos_t *lpos);
57 void pos2lpos_center(pos_t *pos, lpos_t *lpos);
58 void lpos2pos(struct bounds_s *bounds, lpos_t *lpos, pos_t *pos);
59
60 void pos_lat_str(char *str, int len, pos_float_t latitude);
61 void pos_lon_str(char *str, int len, pos_float_t longitude);
62
63 pos_float_t pos_parse_lat(char *str);
64 pos_float_t pos_parse_lon(char *str);
65
66 GtkWidget *pos_lat_entry_new(pos_float_t lat);
67 GtkWidget *pos_lon_entry_new(pos_float_t lon);
68 void pos_lat_entry_set(GtkWidget *label, pos_float_t lat);
69 void pos_lon_entry_set(GtkWidget *label, pos_float_t lon);
70
71 GtkWidget *pos_lat_label_new(pos_float_t lat);
72 GtkWidget *pos_lon_label_new(pos_float_t lon);
73 void pos_lat_label_set(GtkWidget *label, pos_float_t lat);
74 void pos_lon_label_set(GtkWidget *label, pos_float_t lon);
75
76 pos_float_t pos_lat_get(GtkWidget *widget);
77 pos_float_t pos_lon_get(GtkWidget *widget);
78
79 gboolean pos_lat_valid(pos_float_t lat);
80 gboolean pos_lon_valid(pos_float_t lon);
81
82 pos_float_t pos_parse_dist(char *str, gboolean is_mil);
83 void pos_dist_str(char *str, int len, pos_float_t dist, gboolean is_mil);
84 void pos_dist_entry_set(GtkWidget *entry, pos_float_t dist, gboolean is_mil);
85 pos_float_t pos_dist_get(GtkWidget *widget, gboolean is_mil);
86
87 #endif // POS_H