Add:gui_internal:Improved osd keyboard
[navit-package] / navit / coord.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * version 2 as published by the Free Software Foundation.
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 Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef NAVIT_COORD_H
21 #define NAVIT_COORD_H
22
23 #include <stdio.h>
24 #include "config.h"
25 #include "projection.h"
26
27 #define coord_is_equal(a,b) ((a).x==(b).x && (a).y==(b).y)
28
29 /*! A integer mercator coordinate */
30 struct coord {
31         int x; /*!< X-Value */
32         int y; /*!< Y-Value */
33 };
34
35 /*! A integer mercator coordinate carrying its projection */
36 struct pcoord {
37         enum projection pro;
38         int x; /*!< X-Value */
39         int y; /*!< Y-Value */
40 };
41
42 struct coord_rect {
43         struct coord lu;
44         struct coord rl;
45 };
46
47
48 #ifdef AVOID_FLOAT
49 /**
50  * On platforms where we are trying to avoid floats, sometimes we can't.
51  * It is better on these platforms to use single precision floating points
52  * over double percision ones since performance is much better.
53  */
54 typedef float navit_float;
55 #define navit_sin(x) sinf(x)
56 #define navit_cos(x) cosf(x)
57 #define navit_tan(x) tanf(x)
58 #define navit_atan(x) atanf(x)
59 #define navit_acos(x) acosf(x)
60 #define navit_asin(x) asinf(x)
61 #define navit_sqrt(x) sqrtf(x)
62 #else
63 typedef  double navit_float;
64 #define navit_sin(x) sin(x)
65 #define navit_cos(x) cos(x)
66 #define navit_tan(x) tan(x)
67 #define navit_atan(x) atan(x)
68 #define navit_acos(x) acos(x)
69 #define navit_asin(x) asin(x)
70 #define navit_sqrt(x) sqrt(x)
71 #endif
72
73
74 //! A double mercator coordinate
75 struct coord_d {
76         double x; /*!< X-Value */
77         double y; /*!< Y-Value */
78 };
79
80 //! A WGS84 coordinate
81 struct coord_geo {
82         navit_float lng; /*!< Longitude */
83         navit_float lat; /*!< Latitude */
84 };
85
86 //! A cartesian coordinate 
87 struct coord_geo_cart {
88         navit_float x; /*!< X-Value */
89         navit_float y; /*!< Y-Value */
90         navit_float z; /*!< Z-Value */
91 };
92
93 /**
94  * An enumeration of formats for printing geographic coordinates in.
95  *
96  */
97 enum coord_format 
98 {
99         /**
100          * Degrees with decimal places.
101          * Ie 20.5000 N 110.5000 E
102          */
103         DEGREES_DECIMAL,
104
105         /**
106          * Degrees and minutes.
107          * ie 20 30.00 N 110 30.00 E
108          */
109         DEGREES_MINUTES,
110         /**
111          * Degrees, minutes and seconds.
112          * ie 20 30 30.00 N 110 30 30 E
113          */
114         DEGREES_MINUTES_SECONDS 
115 };
116
117 enum projection;
118 struct attr;
119
120 struct coord * coord_get(unsigned char **p);
121 struct coord * coord_new(int x, int y);
122 struct coord * coord_new_from_attrs(struct attr *parent, struct attr **attrs);
123 void coord_destroy(struct coord *c);
124 int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
125 int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *c_ret);
126 void coord_print(enum projection pro, struct coord *c, FILE *out);
127 struct coord_rect * coord_rect_new(struct coord *lu, struct coord *rl);
128 void coord_rect_destroy(struct coord_rect *r);
129 int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
130 int coord_rect_contains(struct coord_rect *r, struct coord *c);
131 void coord_rect_extend(struct coord_rect *r, struct coord *c);
132 void coord_format(float lat,float lng, enum coord_format, char * buffer, int size);
133
134 #endif
135 /* prototypes */
136 enum coord_format;
137 enum projection;
138 struct attr;
139 struct coord;
140 struct coord_rect;
141 struct pcoord;
142 struct coord *coord_get(unsigned char **p);
143 struct coord *coord_new(int x, int y);
144 struct coord *coord_new_from_attrs(struct attr *parent, struct attr **attrs);
145 void coord_destroy(struct coord *c);
146 struct coord_rect *coord_rect_new(struct coord *lu, struct coord *rl);
147 void coord_rect_destroy(struct coord_rect *r);
148 int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
149 int coord_rect_contains(struct coord_rect *r, struct coord *c);
150 void coord_rect_extend(struct coord_rect *r, struct coord *c);
151 int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
152 int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret);
153 void coord_print(enum projection pro, struct coord *c, FILE *out);
154 void coord_format(float lat, float lng, enum coord_format fmt, char *buffer, int size);
155 unsigned int coord_hash(const void *key);
156 int coord_equal(const void *a, const void *b);
157 /* end of prototypes */