1 /***************************************
2 $Header: /home/amb/routino/src/RCS/types.h,v 1.40 2010/05/27 17:25:23 amb Exp $
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
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.
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.
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 ***************************************/
26 #define TYPES_H /*+ To stop multiple inclusions. +*/
33 #define M_PI 3.14159265358979323846
37 /* Constants and macros for handling them */
40 /*+ The latitude and longitude conversion factor from floating point (radians) to integer. +*/
41 #define LAT_LONG_SCALE (1024*65536)
43 /*+ The latitude and longitude integer range within each bin. +*/
44 #define LAT_LONG_BIN 65536
47 /*+ A flag to mark a node as a super-node. +*/
48 #define NODE_SUPER ((index_t)0x80000000)
50 /*+ A segment index excluding the super-node flag. +*/
51 #define SEGMENT(xxx) (index_t)((xxx)&(~NODE_SUPER))
54 /*+ An undefined node index. +*/
55 #define NO_NODE (~(index_t)0)
57 /*+ An undefined segment index. +*/
58 #define NO_SEGMENT (~(index_t)0)
60 /*+ An undefined way index. +*/
61 #define NO_WAY (~(index_t)0)
64 /*+ A flag to mark a segment as one-way from node1 to node2. +*/
65 #define ONEWAY_1TO2 ((distance_t)0x80000000)
67 /*+ A flag to mark a segment as one-way node2 to node1. +*/
68 #define ONEWAY_2TO1 ((distance_t)0x40000000)
70 /*+ A flag to mark a segment as a super-segment. +*/
71 #define SEGMENT_SUPER ((distance_t)0x20000000)
73 /*+ A flag to mark a segment as a normal segment. +*/
74 #define SEGMENT_NORMAL ((distance_t)0x10000000)
76 /*+ The real distance ignoring the ONEWAY_* and SEGMENT_* flags. +*/
77 #define DISTANCE(xx) ((distance_t)(xx)&(~(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL)))
79 /*+ The distance flags selecting only the ONEWAY_* and SEGMENT_* flags. +*/
80 #define DISTFLAG(xx) ((distance_t)(xx)&(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL))
83 /*+ A very large almost infinite distance. +*/
84 #define INF_DISTANCE DISTANCE(~0)
86 /*+ A very large almost infinite score. +*/
87 #define INF_SCORE (score_t)1E30
93 /*+ A node, segment or way index. +*/
94 typedef uint32_t index_t;
97 /*+ A node latitude or longitude. +*/
98 typedef int32_t latlong_t;
100 /*+ A node latitude or longitude bin number. +*/
101 typedef int16_t ll_bin_t;
103 /*+ A node latitude or longitude offset. +*/
104 typedef uint16_t ll_off_t;
107 /*+ Conversion from a latlong (integer latitude or longitude) to a bin number. +*/
108 #define latlong_to_bin(xxx) (ll_bin_t)((latlong_t)((xxx)&~(LAT_LONG_BIN-1))/LAT_LONG_BIN)
110 /*+ Conversion from a bin number to a latlong (integer latitude or longitude). +*/
111 #define bin_to_latlong(xxx) ((latlong_t)(xxx)*LAT_LONG_BIN)
113 /*+ Conversion from a latlong (integer latitude or longitude) to a bin offset. +*/
114 #define latlong_to_off(xxx) (ll_off_t)((latlong_t)(xxx)&(LAT_LONG_BIN-1))
116 /*+ Conversion from a bin offset to a latlong (integer latitude or longitude). +*/
117 #define off_to_latlong(xxx) ((latlong_t)(xxx))
120 /*+ Conversion from a latitude or longitude in radians to a latlong (integer latitude or longitude). +*/
121 #define radians_to_latlong(xxx) ((latlong_t)floor((xxx)*LAT_LONG_SCALE))
123 /*+ Conversion from a latlong (integer latitude or longitude) to a latitude or longitude in radians. +*/
124 #define latlong_to_radians(xxx) ((double)(xxx)/LAT_LONG_SCALE)
127 /*+ Conversion from radians to degrees. +*/
128 #define radians_to_degrees(xxx) ((xxx)*(180.0/M_PI))
130 /*+ Conversion from degrees to radians. +*/
131 #define degrees_to_radians(xxx) ((xxx)*(M_PI/180.0))
134 /*+ A distance, measured in metres. +*/
135 typedef uint32_t distance_t;
137 /*+ A duration, measured in 1/10th seconds. +*/
138 typedef uint32_t duration_t;
140 /*+ A routing optimisation score. +*/
141 typedef float score_t;
144 /*+ Conversion from distance_t to kilometres. +*/
145 #define distance_to_km(xx) ((double)(xx)/1000.0)
147 /*+ Conversion from metres to distance_t. +*/
148 #define km_to_distance(xx) ((distance_t)((double)(xx)*1000.0))
150 /*+ Conversion from duration_t to minutes. +*/
151 #define duration_to_minutes(xx) ((double)(xx)/600.0)
153 /*+ Conversion from duration_t to hours. +*/
154 #define duration_to_hours(xx) ((double)(xx)/36000.0)
156 /*+ Conversion from hours to duration_t. +*/
157 #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0))
159 /*+ Conversion from distance_t and speed_t to duration_t. +*/
160 #define distance_speed_to_duration(xx,yy) ((duration_t)(((double)(xx)/(double)(yy))*(36000.0/1000.0)))
163 /*+ The type of a way. +*/
164 typedef uint8_t waytype_t;
166 /*+ The different types of a way. +*/
167 typedef enum _Highway
182 Way_Count =13, /* One more than the number of highway types. */
189 #define HIGHWAY(xx) ((xx)&0x1f)
192 /*+ The different methods of transport. +*/
193 typedef enum _Transport
199 Transport_Wheelchair = 3,
200 Transport_Bicycle = 4,
202 Transport_Motorbike = 6,
203 Transport_Motorcar = 7,
208 Transport_Count = 11 /*+ One more than the number of transport types. +*/
213 /*+ The allowed traffic on a way. +*/
214 typedef uint16_t wayallow_t;
216 #define ALLOWED(xx) (1<<((xx)-1))
218 /*+ The different allowed traffic on a way. +*/
219 typedef enum _Allowed
221 Allow_Foot = ALLOWED(Transport_Foot ),
222 Allow_Horse = ALLOWED(Transport_Horse ),
223 Allow_Wheelchair = ALLOWED(Transport_Wheelchair),
224 Allow_Bicycle = ALLOWED(Transport_Bicycle ),
225 Allow_Moped = ALLOWED(Transport_Moped ),
226 Allow_Motorbike = ALLOWED(Transport_Motorbike ),
227 Allow_Motorcar = ALLOWED(Transport_Motorcar ),
228 Allow_Goods = ALLOWED(Transport_Goods ),
229 Allow_HGV = ALLOWED(Transport_HGV ),
230 Allow_PSV = ALLOWED(Transport_PSV ),
237 /*+ The individual properties of a highway. +*/
238 typedef enum _Property
243 Property_Multilane = 2,
247 Property_Count = 5 /* One more than the number of property types. */
252 /*+ The combined set of properties of a way. +*/
253 typedef uint8_t wayprop_t;
255 #define PROPERTIES(xx) (1<<((xx)-1))
257 /*+ The different properties of a way. +*/
258 typedef enum _Properties
260 Properties_Paved = PROPERTIES(Property_Paved),
261 Properties_Multilane = PROPERTIES(Property_Multilane),
262 Properties_Bridge = PROPERTIES(Property_Bridge),
263 Properties_Tunnel = PROPERTIES(Property_Tunnel),
270 /*+ The speed limit of a way, measured in km/hour. +*/
271 typedef uint8_t speed_t;
273 /*+ The maximum weight of a way, measured in 0.2 tonnes. +*/
274 typedef uint8_t weight_t;
276 /*+ The maximum height of a way, measured in 0.1 metres. +*/
277 typedef uint8_t height_t;
279 /*+ The maximum width of a way, measured in 0.1 metres. +*/
280 typedef uint8_t width_t;
282 /*+ The maximum length of a way, measured in 0.1 metres. +*/
283 typedef uint8_t length_t;
286 /*+ Conversion of km/hr to speed_t. +*/
287 #define kph_to_speed(xxx) (speed_t)(xxx)
289 /*+ Conversion of speed_t to km/hr. +*/
290 #define speed_to_kph(xxx) (int)(xxx)
292 /*+ Conversion of tonnes to weight_t. +*/
293 #define tonnes_to_weight(xxx) (weight_t)((xxx)*5)
295 /*+ Conversion of weight_t to tonnes. +*/
296 #define weight_to_tonnes(xxx) ((double)(xxx)/5.0)
298 /*+ Conversion of metres to height_t. +*/
299 #define metres_to_height(xxx) (height_t)((xxx)*10)
301 /*+ Conversion of height_t to metres. +*/
302 #define height_to_metres(xxx) ((double)(xxx)/10.0)
304 /*+ Conversion of metres to width_t. +*/
305 #define metres_to_width(xxx) (width_t)((xxx)*10)
307 /*+ Conversion of width_t to metres. +*/
308 #define width_to_metres(xxx) ((double)(xxx)/10.0)
310 /*+ Conversion of metres to length_t. +*/
311 #define metres_to_length(xxx) (length_t)((xxx)*10)
313 /*+ Conversion of length_t to metres. +*/
314 #define length_to_metres(xxx) ((double)(xxx)/10.0)
317 /* Data structures */
319 typedef struct _Node Node;
321 typedef struct _Nodes Nodes;
323 typedef struct _Segment Segment;
325 typedef struct _Segments Segments;
327 typedef struct _Way Way;
329 typedef struct _Ways Ways;
334 Highway HighwayType(const char *highway);
335 Transport TransportType(const char *transport);
336 Property PropertyType(const char *property);
338 const char *HighwayName(Highway highway);
339 const char *TransportName(Transport transport);
340 const char *PropertyName(Property property);
342 const char *AllowedNameList(wayallow_t allowed);
343 const char *PropertiesNameList(wayprop_t properties);
345 const char *HighwayList(void);
346 const char *TransportList(void);
347 const char *PropertyList(void);