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 469 - (show annotations) (download) (as text)
Mon Aug 2 18:47:09 2010 UTC (14 years, 7 months ago) by amb
File MIME type: text/x-chdr
File size: 9944 byte(s)
Understand node traffic type restrictions.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/types.h,v 1.44 2010-08-02 18:44:54 amb Exp $
3
4 Type definitions
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 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 /*+ An undefined node index. +*/
48 #define NO_NODE (~(index_t)0)
49
50 /*+ An undefined segment index. +*/
51 #define NO_SEGMENT (~(index_t)0)
52
53 /*+ An undefined way index. +*/
54 #define NO_WAY (~(index_t)0)
55
56
57 /*+ A flag to mark a node as a fake node. +*/
58 #define NODE_FAKE ((index_t)0x80000000)
59
60 /*+ A flag to mark a segment as a fake node. +*/
61 #define SEGMENT_FAKE ((index_t)0x80000000)
62
63
64 /*+ A flag to mark a node as a super-node. +*/
65 #define NODE_SUPER ((index_t)0x80000000)
66
67 /*+ The set of allowed transports through a node. +*/
68 #define NODEALLOW(xx) ((allow_t)((xx)&Allow_ALL))
69
70
71 /*+ A flag to mark a segment as one-way from node1 to node2. +*/
72 #define ONEWAY_1TO2 ((distance_t)0x80000000)
73
74 /*+ A flag to mark a segment as one-way node2 to node1. +*/
75 #define ONEWAY_2TO1 ((distance_t)0x40000000)
76
77 /*+ A flag to mark a segment as a super-segment. +*/
78 #define SEGMENT_SUPER ((distance_t)0x20000000)
79
80 /*+ A flag to mark a segment as a normal segment. +*/
81 #define SEGMENT_NORMAL ((distance_t)0x10000000)
82
83 /*+ The real distance ignoring the ONEWAY_* and SEGMENT_* flags. +*/
84 #define DISTANCE(xx) ((distance_t)((xx)&(~(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL))))
85
86 /*+ The distance flags selecting only the ONEWAY_* and SEGMENT_* flags. +*/
87 #define DISTFLAG(xx) ((distance_t)((xx)&(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL)))
88
89
90 /*+ A very large almost infinite distance. +*/
91 #define INF_DISTANCE DISTANCE(~0)
92
93 /*+ A very large almost infinite score. +*/
94 #define INF_SCORE (score_t)1E30
95
96
97 /* Simple Types */
98
99
100 /*+ A node, segment or way index. +*/
101 typedef uint32_t index_t;
102
103
104 /*+ A node latitude or longitude. +*/
105 typedef int32_t latlong_t;
106
107 /*+ A node latitude or longitude bin number. +*/
108 typedef int16_t ll_bin_t;
109
110 /*+ A node latitude or longitude offset. +*/
111 typedef uint16_t ll_off_t;
112
113
114 /*+ Conversion from a latlong (integer latitude or longitude) to a bin number. +*/
115 #define latlong_to_bin(xxx) (ll_bin_t)((latlong_t)((xxx)&~(LAT_LONG_BIN-1))/LAT_LONG_BIN)
116
117 /*+ Conversion from a bin number to a latlong (integer latitude or longitude). +*/
118 #define bin_to_latlong(xxx) ((latlong_t)(xxx)*LAT_LONG_BIN)
119
120 /*+ Conversion from a latlong (integer latitude or longitude) to a bin offset. +*/
121 #define latlong_to_off(xxx) (ll_off_t)((latlong_t)(xxx)&(LAT_LONG_BIN-1))
122
123 /*+ Conversion from a bin offset to a latlong (integer latitude or longitude). +*/
124 #define off_to_latlong(xxx) ((latlong_t)(xxx))
125
126
127 /*+ Conversion from a latitude or longitude in radians to a latlong (integer latitude or longitude). +*/
128 #define radians_to_latlong(xxx) ((latlong_t)floor((xxx)*LAT_LONG_SCALE))
129
130 /*+ Conversion from a latlong (integer latitude or longitude) to a latitude or longitude in radians. +*/
131 #define latlong_to_radians(xxx) ((double)(xxx)/LAT_LONG_SCALE)
132
133
134 /*+ Conversion from radians to degrees. +*/
135 #define radians_to_degrees(xxx) ((xxx)*(180.0/M_PI))
136
137 /*+ Conversion from degrees to radians. +*/
138 #define degrees_to_radians(xxx) ((xxx)*(M_PI/180.0))
139
140
141 /*+ A distance, measured in metres. +*/
142 typedef uint32_t distance_t;
143
144 /*+ A duration, measured in 1/10th seconds. +*/
145 typedef uint32_t duration_t;
146
147 /*+ A routing optimisation score. +*/
148 typedef float score_t;
149
150
151 /*+ Conversion from distance_t to kilometres. +*/
152 #define distance_to_km(xx) ((double)(xx)/1000.0)
153
154 /*+ Conversion from metres to distance_t. +*/
155 #define km_to_distance(xx) ((distance_t)((double)(xx)*1000.0))
156
157 /*+ Conversion from duration_t to minutes. +*/
158 #define duration_to_minutes(xx) ((double)(xx)/600.0)
159
160 /*+ Conversion from duration_t to hours. +*/
161 #define duration_to_hours(xx) ((double)(xx)/36000.0)
162
163 /*+ Conversion from hours to duration_t. +*/
164 #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0))
165
166 /*+ Conversion from distance_t and speed_t to duration_t. +*/
167 #define distance_speed_to_duration(xx,yy) ((duration_t)(((double)(xx)/(double)(yy))*(36000.0/1000.0)))
168
169
170 /*+ The type of a way. +*/
171 typedef uint8_t waytype_t;
172
173 /*+ The different types of a way. +*/
174 typedef enum _Highway
175 {
176 Way_Motorway = 1,
177 Way_Trunk = 2,
178 Way_Primary = 3,
179 Way_Secondary = 4,
180 Way_Tertiary = 5,
181 Way_Unclassified= 6,
182 Way_Residential = 7,
183 Way_Service = 8,
184 Way_Track = 9,
185 Way_Cycleway =10,
186 Way_Path =11,
187 Way_Steps =12,
188
189 Way_Count =13, /* One more than the number of highway types. */
190
191 Way_OneWay =32,
192 Way_Roundabout =64
193 }
194 Highway;
195
196 #define HIGHWAY(xx) ((xx)&0x1f)
197
198
199 /*+ The different methods of transport. +*/
200 typedef enum _Transport
201 {
202 Transport_None = 0,
203
204 Transport_Foot = 1,
205 Transport_Horse = 2,
206 Transport_Wheelchair = 3,
207 Transport_Bicycle = 4,
208 Transport_Moped = 5,
209 Transport_Motorbike = 6,
210 Transport_Motorcar = 7,
211 Transport_Goods = 8,
212 Transport_HGV = 9,
213 Transport_PSV = 10,
214
215 Transport_Count = 11 /*+ One more than the number of transport types. +*/
216 }
217 Transport;
218
219
220 /*+ The allowed traffic on a way. +*/
221 typedef uint16_t allow_t;
222
223 #define ALLOWED(xx) (1<<((xx)-1))
224
225 /*+ The different allowed traffic on a way. +*/
226 typedef enum _Allowed
227 {
228 Allow_Foot = ALLOWED(Transport_Foot ),
229 Allow_Horse = ALLOWED(Transport_Horse ),
230 Allow_Wheelchair = ALLOWED(Transport_Wheelchair),
231 Allow_Bicycle = ALLOWED(Transport_Bicycle ),
232 Allow_Moped = ALLOWED(Transport_Moped ),
233 Allow_Motorbike = ALLOWED(Transport_Motorbike ),
234 Allow_Motorcar = ALLOWED(Transport_Motorcar ),
235 Allow_Goods = ALLOWED(Transport_Goods ),
236 Allow_HGV = ALLOWED(Transport_HGV ),
237 Allow_PSV = ALLOWED(Transport_PSV ),
238
239 Allow_ALL = 65535
240 }
241 Allowed;
242
243
244 /*+ The individual properties of a highway. +*/
245 typedef enum _Property
246 {
247 Property_None = 0,
248
249 Property_Paved = 1,
250 Property_Multilane = 2,
251 Property_Bridge = 3,
252 Property_Tunnel = 4,
253
254 Property_Count = 5 /* One more than the number of property types. */
255 }
256 Property;
257
258
259 /*+ The combined set of properties of a way. +*/
260 typedef uint8_t wayprop_t;
261
262 #define PROPERTIES(xx) (1<<((xx)-1))
263
264 /*+ The different properties of a way. +*/
265 typedef enum _Properties
266 {
267 Properties_Paved = PROPERTIES(Property_Paved),
268 Properties_Multilane = PROPERTIES(Property_Multilane),
269 Properties_Bridge = PROPERTIES(Property_Bridge),
270 Properties_Tunnel = PROPERTIES(Property_Tunnel),
271
272 Properties_ALL = 255
273 }
274 Properties;
275
276
277 /*+ The speed limit of a way, measured in km/hour. +*/
278 typedef uint8_t speed_t;
279
280 /*+ The maximum weight of a way, measured in 0.2 tonnes. +*/
281 typedef uint8_t weight_t;
282
283 /*+ The maximum height of a way, measured in 0.1 metres. +*/
284 typedef uint8_t height_t;
285
286 /*+ The maximum width of a way, measured in 0.1 metres. +*/
287 typedef uint8_t width_t;
288
289 /*+ The maximum length of a way, measured in 0.1 metres. +*/
290 typedef uint8_t length_t;
291
292
293 /*+ Conversion of km/hr to speed_t. +*/
294 #define kph_to_speed(xxx) (speed_t)(xxx)
295
296 /*+ Conversion of speed_t to km/hr. +*/
297 #define speed_to_kph(xxx) (int)(xxx)
298
299 /*+ Conversion of tonnes to weight_t. +*/
300 #define tonnes_to_weight(xxx) (weight_t)((xxx)*5)
301
302 /*+ Conversion of weight_t to tonnes. +*/
303 #define weight_to_tonnes(xxx) ((double)(xxx)/5.0)
304
305 /*+ Conversion of metres to height_t. +*/
306 #define metres_to_height(xxx) (height_t)((xxx)*10)
307
308 /*+ Conversion of height_t to metres. +*/
309 #define height_to_metres(xxx) ((double)(xxx)/10.0)
310
311 /*+ Conversion of metres to width_t. +*/
312 #define metres_to_width(xxx) (width_t)((xxx)*10)
313
314 /*+ Conversion of width_t to metres. +*/
315 #define width_to_metres(xxx) ((double)(xxx)/10.0)
316
317 /*+ Conversion of metres to length_t. +*/
318 #define metres_to_length(xxx) (length_t)((xxx)*10)
319
320 /*+ Conversion of length_t to metres. +*/
321 #define length_to_metres(xxx) ((double)(xxx)/10.0)
322
323
324 /* Data structures */
325
326 typedef struct _Node Node;
327
328 typedef struct _Nodes Nodes;
329
330 typedef struct _Segment Segment;
331
332 typedef struct _Segments Segments;
333
334 typedef struct _Way Way;
335
336 typedef struct _Ways Ways;
337
338
339 /* Functions */
340
341 Highway HighwayType(const char *highway);
342 Transport TransportType(const char *transport);
343 Property PropertyType(const char *property);
344
345 const char *HighwayName(Highway highway);
346 const char *TransportName(Transport transport);
347 const char *PropertyName(Property property);
348
349 const char *AllowedNameList(allow_t allowed);
350 const char *PropertiesNameList(wayprop_t properties);
351
352 const char *HighwayList(void);
353 const char *TransportList(void);
354 const char *PropertyList(void);
355
356
357 #endif /* TYPES_H */

Properties

Name Value
cvs:description Data type definitions.