Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/types.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 219 - (show annotations) (download) (as text)
Thu Jul 9 17:31:56 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 7927 byte(s)
Change from float to double for latitude and longitude.
Store latitude and longitude as an integer type rather than float (higher precision).

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/types.h,v 1.27 2009-07-09 17:31:56 amb Exp $
3
4 Type definitions
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008,2009 Andrew M. Bishop
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
23
24
25 #ifndef TYPES_H
26 #define TYPES_H /*+ To stop multiple inclusions. +*/
27
28 #include <stdint.h>
29 #include <math.h>
30
31
32 #ifndef M_PI
33 #define M_PI 3.14159265358979323846
34 #endif
35
36
37 /* Constants and macros for handling them */
38
39
40 /*+ The latitude and longitude conversion factor from floating point (radians) to integer. +*/
41 #define LAT_LONG_SCALE (1024*65536)
42
43 /*+ The latitude and longitude integer range within each bin. +*/
44 #define LAT_LONG_BIN 65536
45
46
47 /*+ A flag to mark a node as a super-node. +*/
48 #define NODE_SUPER ((index_t)0x80000000)
49
50 /*+ A segment index excluding the super-node flag. +*/
51 #define SEGMENT(xxx) (index_t)((xxx)&(~NODE_SUPER))
52
53 /*+ An undefined node index. +*/
54 #define NO_NODE (~(index_t)0)
55
56 /*+ An undefined segment index. +*/
57 #define NO_SEGMENT (~(index_t)0)
58
59 /*+ An undefined way index. +*/
60 #define NO_WAY (~(index_t)0)
61
62
63 /*+ A flag to mark a segment as one-way from node1 to node2. +*/
64 #define ONEWAY_1TO2 ((distance_t)0x80000000)
65
66 /*+ A flag to mark a segment as one-way node2 to node1. +*/
67 #define ONEWAY_2TO1 ((distance_t)0x40000000)
68
69 /*+ A flag to mark a segment as a super-segment. +*/
70 #define SEGMENT_SUPER ((distance_t)0x20000000)
71
72 /*+ A flag to mark a segment as a normal segment. +*/
73 #define SEGMENT_NORMAL ((distance_t)0x10000000)
74
75 /*+ The real distance ignoring the ONEWAY_* and SEGMENT_* flags. +*/
76 #define DISTANCE(xx) (distance_t)((xx)&(~(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL)))
77
78
79 /*+ A very large almost infinite score. +*/
80 #define INF_SCORE (score_t)1E30
81
82
83 /* Simple Types */
84
85
86 /*+ A node, segment or way index. +*/
87 typedef uint32_t index_t;
88
89
90 /*+ A node latitude or longitude. +*/
91 typedef int32_t latlong_t;
92
93 /*+ A node latitude or longitude bin number. +*/
94 typedef int16_t ll_bin_t;
95
96 /*+ A node latitude or longitude offset. +*/
97 typedef uint16_t ll_off_t;
98
99
100 /*+ Conversion from a latlong (integer latitude or longitude) to a bin number. +*/
101 #define latlong_to_bin(xxx) (ll_bin_t)((latlong_t)((xxx)&~(LAT_LONG_BIN-1))/LAT_LONG_BIN)
102
103 /*+ Conversion from a bin number to a latlong (integer latitude or longitude). +*/
104 #define bin_to_latlong(xxx) ((latlong_t)(xxx)*LAT_LONG_BIN)
105
106 /*+ Conversion from a latlong (integer latitude or longitude) to a bin offset. +*/
107 #define latlong_to_off(xxx) (ll_off_t)((latlong_t)(xxx)&(LAT_LONG_BIN-1))
108
109 /*+ Conversion from a bin offset to a latlong (integer latitude or longitude). +*/
110 #define off_to_latlong(xxx) ((latlong_t)(xxx))
111
112
113 /*+ Conversion from a latitude or longitude in radians to a latlong (integer latitude or longitude). +*/
114 #define radians_to_latlong(xxx) ((latlong_t)floor((xxx)*LAT_LONG_SCALE))
115
116 /*+ Conversion from a latlong (integer latitude or longitude) to a latitude or longitude in radians. +*/
117 #define latlong_to_radians(xxx) ((double)(xxx)/LAT_LONG_SCALE)
118
119
120 /*+ Conversion from radians to degrees. +*/
121 #define radians_to_degrees(xxx) ((xxx)*(180.0/M_PI))
122
123 /*+ Conversion from degrees to radians. +*/
124 #define degrees_to_radians(xxx) ((xxx)*(M_PI/180.0))
125
126
127 /*+ A distance, measured in metres. +*/
128 typedef uint32_t distance_t;
129
130 /*+ A duration, measured in 1/10th seconds. +*/
131 typedef uint32_t duration_t;
132
133 /*+ A routing optimisation score. +*/
134 typedef float score_t;
135
136
137 /*+ Conversion from distance_t to kilometres. +*/
138 #define distance_to_km(xx) ((double)(xx)/1000.0)
139
140 /*+ Conversion from metres to distance_t. +*/
141 #define km_to_distance(xx) ((distance_t)((double)(xx)*1000.0))
142
143 /*+ Conversion from duration_t to minutes. +*/
144 #define duration_to_minutes(xx) ((double)(xx)/600.0)
145
146 /*+ Conversion from duration_t to hours. +*/
147 #define duration_to_hours(xx) ((double)(xx)/36000.0)
148
149 /*+ Conversion from hours to duration_t. +*/
150 #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0))
151
152 /*+ Conversion from distance_t and speed_t to duration_t. +*/
153 #define distance_speed_to_duration(xx,yy) ((duration_t)(((double)(xx)/(double)(yy))*(36000.0/1000.0)))
154
155
156 /*+ The type of a way. +*/
157 typedef uint8_t waytype_t;
158
159 /*+ The different types of a way. +*/
160 typedef enum _Highway
161 {
162 Way_Motorway = 1,
163 Way_Trunk = 2,
164 Way_Primary = 3,
165 Way_Secondary = 4,
166 Way_Tertiary = 5,
167 Way_Unclassified= 6,
168 Way_Residential = 7,
169 Way_Service = 8,
170 Way_Track = 9,
171 Way_Path =10,
172 Way_Bridleway =11,
173 Way_Cycleway =12,
174 Way_Footway =13,
175
176 Way_Unknown =14,
177
178 Way_OneWay =32,
179 Way_Roundabout =64
180 }
181 Highway;
182
183 #define HIGHWAY(xx) ((xx)&0x0f)
184
185
186 /*+ The method of transport. +*/
187 typedef uint8_t transport_t;
188
189 /*+ The different methods of transport. +*/
190 typedef enum _Transport
191 {
192 Transport_None = 0,
193
194 Transport_Foot = 1,
195 Transport_Bicycle = 2,
196 Transport_Horse = 3,
197 Transport_Motorbike = 4,
198 Transport_Motorcar = 5,
199 Transport_Goods = 6,
200 Transport_HGV = 7,
201 Transport_PSV = 8
202 }
203 Transport;
204
205
206 /*+ The allowed traffic on a way. +*/
207 typedef uint8_t wayallow_t;
208
209 /*+ The different allowed traffic on a way. +*/
210 typedef enum _Allowed
211 {
212 Allow_Foot =1<<(Transport_Foot -1),
213 Allow_Bicycle =1<<(Transport_Bicycle -1),
214 Allow_Horse =1<<(Transport_Horse -1),
215 Allow_Motorbike =1<<(Transport_Motorbike-1),
216 Allow_Motorcar =1<<(Transport_Motorcar -1),
217 Allow_Goods =1<<(Transport_Goods -1),
218 Allow_HGV =1<<(Transport_HGV -1),
219 Allow_PSV =1<<(Transport_PSV -1),
220
221 Allow_ALL =255
222 }
223 Allowed;
224
225
226 /*+ The speed limit of a way, measured in km/hour. +*/
227 typedef uint8_t speed_t;
228
229 /*+ The maximum weight of a way, measured in 0.2 tonnes. +*/
230 typedef uint8_t weight_t;
231
232 /*+ The maximum height of a way, measured in 0.1 metres. +*/
233 typedef uint8_t height_t;
234
235 /*+ The maximum width of a way, measured in 0.1 metres. +*/
236 typedef uint8_t width_t;
237
238 /*+ The maximum length of a way, measured in 0.1 metres. +*/
239 typedef uint8_t length_t;
240
241
242 /*+ Conversion of km/hr to speed_t. +*/
243 #define kph_to_speed(xxx) (speed_t)(xxx)
244
245 /*+ Conversion of speed_t to km/hr. +*/
246 #define speed_to_kph(xxx) (int)(xxx)
247
248 /*+ Conversion of tonnes to weight_t. +*/
249 #define tonnes_to_weight(xxx) (weight_t)((xxx)*5)
250
251 /*+ Conversion of weight_t to tonnes. +*/
252 #define weight_to_tonnes(xxx) ((double)(xxx)/5.0)
253
254 /*+ Conversion of metres to height_t. +*/
255 #define metres_to_height(xxx) (height_t)((xxx)*10)
256
257 /*+ Conversion of height_t to metres. +*/
258 #define height_to_metres(xxx) ((double)(xxx)/10.0)
259
260 /*+ Conversion of metres to width_t. +*/
261 #define metres_to_width(xxx) (width_t)((xxx)*10)
262
263 /*+ Conversion of width_t to metres. +*/
264 #define width_to_metres(xxx) ((double)(xxx)/10.0)
265
266 /*+ Conversion of metres to length_t. +*/
267 #define metres_to_length(xxx) (length_t)((xxx)*10)
268
269 /*+ Conversion of length_t to metres. +*/
270 #define length_to_metres(xxx) ((double)(xxx)/10.0)
271
272
273 /* Data structures */
274
275 typedef struct _Node Node;
276
277 typedef struct _Nodes Nodes;
278
279 typedef struct _Segment Segment;
280
281 typedef struct _Segments Segments;
282
283 typedef struct _Way Way;
284
285 typedef struct _Ways Ways;
286
287
288 #endif /* TYPES_H */

Properties

Name Value
cvs:description Data type definitions.