1 /***************************************
2 $Header: /home/amb/routino/src/RCS/types.h,v 1.48 2010/09/17 17:43:41 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 */
39 /*+ An undefined node index. +*/
40 #define NO_NODE (~(index_t)0)
42 /*+ An undefined segment index. +*/
43 #define NO_SEGMENT (~(index_t)0)
45 /*+ An undefined way index. +*/
46 #define NO_WAY (~(index_t)0)
49 /*+ The lowest number allowed for a fake node. +*/
50 #define NODE_FAKE ((index_t)0xffff0000)
52 /*+ The lowest number allowed for a fake segment. +*/
53 #define SEGMENT_FAKE ((index_t)0xffff0000)
56 /*+ The latitude and longitude conversion factor from floating point (radians) to integer. +*/
57 #define LAT_LONG_SCALE (1024*65536)
59 /*+ The latitude and longitude integer range within each bin. +*/
60 #define LAT_LONG_BIN 65536
62 /*+ A flag to mark a node as a super-node. +*/
63 #define NODE_SUPER ((uint16_t)0x8000)
66 /*+ A flag to mark a segment as one-way from node1 to node2. +*/
67 #define ONEWAY_1TO2 ((distance_t)0x80000000)
69 /*+ A flag to mark a segment as one-way node2 to node1. +*/
70 #define ONEWAY_2TO1 ((distance_t)0x40000000)
72 /*+ A flag to mark a segment as a super-segment. +*/
73 #define SEGMENT_SUPER ((distance_t)0x20000000)
75 /*+ A flag to mark a segment as a normal segment. +*/
76 #define SEGMENT_NORMAL ((distance_t)0x10000000)
78 /*+ The real distance ignoring the ONEWAY_* and SEGMENT_* flags. +*/
79 #define DISTANCE(xx) ((distance_t)((xx)&(~(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL))))
81 /*+ The distance flags selecting only the ONEWAY_* and SEGMENT_* flags. +*/
82 #define DISTFLAG(xx) ((distance_t)((xx)&(ONEWAY_1TO2|ONEWAY_2TO1|SEGMENT_SUPER|SEGMENT_NORMAL)))
85 /*+ A very large almost infinite distance. +*/
86 #define INF_DISTANCE DISTANCE(~0)
88 /*+ A very large almost infinite score. +*/
89 #define INF_SCORE (score_t)1E30
95 /*+ A node, segment or way index. +*/
96 typedef uint32_t index_t;
99 /*+ A node latitude or longitude. +*/
100 typedef int32_t latlong_t;
102 /*+ A node latitude or longitude bin number. +*/
103 typedef int16_t ll_bin_t;
105 /*+ A node latitude or longitude offset. +*/
106 typedef uint16_t ll_off_t;
109 /*+ Conversion from a latlong (integer latitude or longitude) to a bin number. +*/
110 #define latlong_to_bin(xxx) (ll_bin_t)((latlong_t)((xxx)&~(LAT_LONG_BIN-1))/LAT_LONG_BIN)
112 /*+ Conversion from a bin number to a latlong (integer latitude or longitude). +*/
113 #define bin_to_latlong(xxx) ((latlong_t)(xxx)*LAT_LONG_BIN)
115 /*+ Conversion from a latlong (integer latitude or longitude) to a bin offset. +*/
116 #define latlong_to_off(xxx) (ll_off_t)((latlong_t)(xxx)&(LAT_LONG_BIN-1))
118 /*+ Conversion from a bin offset to a latlong (integer latitude or longitude). +*/
119 #define off_to_latlong(xxx) ((latlong_t)(xxx))
122 /*+ Conversion from a latitude or longitude in radians to a latlong (integer latitude or longitude). +*/
123 #define radians_to_latlong(xxx) ((latlong_t)floor((xxx)*LAT_LONG_SCALE))
125 /*+ Conversion from a latlong (integer latitude or longitude) to a latitude or longitude in radians. +*/
126 #define latlong_to_radians(xxx) ((double)(xxx)/LAT_LONG_SCALE)
129 /*+ Conversion from radians to degrees. +*/
130 #define radians_to_degrees(xxx) ((xxx)*(180.0/M_PI))
132 /*+ Conversion from degrees to radians. +*/
133 #define degrees_to_radians(xxx) ((xxx)*(M_PI/180.0))
136 /*+ A distance, measured in metres. +*/
137 typedef uint32_t distance_t;
139 /*+ A duration, measured in 1/10th seconds. +*/
140 typedef uint32_t duration_t;
142 /*+ A routing optimisation score. +*/
143 typedef float score_t;
146 /*+ Conversion from distance_t to kilometres. +*/
147 #define distance_to_km(xx) ((double)(xx)/1000.0)
149 /*+ Conversion from metres to distance_t. +*/
150 #define km_to_distance(xx) ((distance_t)((double)(xx)*1000.0))
152 /*+ Conversion from duration_t to minutes. +*/
153 #define duration_to_minutes(xx) ((double)(xx)/600.0)
155 /*+ Conversion from duration_t to hours. +*/
156 #define duration_to_hours(xx) ((double)(xx)/36000.0)
158 /*+ Conversion from hours to duration_t. +*/
159 #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0))
161 /*+ Conversion from distance_t and speed_t to duration_t. +*/
162 #define distance_speed_to_duration(xx,yy) ((duration_t)(((double)(xx)/(double)(yy))*(36000.0/1000.0)))
165 /*+ The type of a way. +*/
166 typedef uint8_t waytype_t;
168 /*+ The different types of a way. +*/
169 typedef enum _Highway
185 Way_Count =14, /* One more than the number of highway types. */
192 #define HIGHWAY(xx) ((xx)&0x1f)
195 /*+ The different methods of transport. +*/
196 typedef enum _Transport
202 Transport_Wheelchair = 3,
203 Transport_Bicycle = 4,
205 Transport_Motorbike = 6,
206 Transport_Motorcar = 7,
211 Transport_Count = 11 /*+ One more than the number of transport types. +*/
216 /*+ The allowed traffic on a way. +*/
217 typedef uint16_t allow_t;
219 #define ALLOWED(xx) (1<<((xx)-1))
221 /*+ The different allowed traffic on a way. +*/
222 typedef enum _Allowed
226 Allow_Foot = ALLOWED(Transport_Foot ),
227 Allow_Horse = ALLOWED(Transport_Horse ),
228 Allow_Wheelchair = ALLOWED(Transport_Wheelchair),
229 Allow_Bicycle = ALLOWED(Transport_Bicycle ),
230 Allow_Moped = ALLOWED(Transport_Moped ),
231 Allow_Motorbike = ALLOWED(Transport_Motorbike ),
232 Allow_Motorcar = ALLOWED(Transport_Motorcar ),
233 Allow_Goods = ALLOWED(Transport_Goods ),
234 Allow_HGV = ALLOWED(Transport_HGV ),
235 Allow_PSV = ALLOWED(Transport_PSV ),
242 /*+ The individual properties of a highway. +*/
243 typedef enum _Property
248 Property_Multilane = 2,
251 Property_FootRoute = 5,
252 Property_BicycleRoute = 6,
254 Property_Count = 7 /* One more than the number of property types. */
259 /*+ The combined set of properties of a way. +*/
260 typedef uint8_t wayprop_t;
262 #define PROPERTIES(xx) (1<<((xx)-1))
264 /*+ The different properties of a way. +*/
265 typedef enum _Properties
269 Properties_Paved = PROPERTIES(Property_Paved),
270 Properties_Multilane = PROPERTIES(Property_Multilane),
271 Properties_Bridge = PROPERTIES(Property_Bridge),
272 Properties_Tunnel = PROPERTIES(Property_Tunnel),
273 Properties_FootRoute = PROPERTIES(Property_FootRoute),
274 Properties_BicycleRoute = PROPERTIES(Property_BicycleRoute),
281 /*+ The speed limit of a way, measured in km/hour. +*/
282 typedef uint8_t speed_t;
284 /*+ The maximum weight of a way, measured in 0.2 tonnes. +*/
285 typedef uint8_t weight_t;
287 /*+ The maximum height of a way, measured in 0.1 metres. +*/
288 typedef uint8_t height_t;
290 /*+ The maximum width of a way, measured in 0.1 metres. +*/
291 typedef uint8_t width_t;
293 /*+ The maximum length of a way, measured in 0.1 metres. +*/
294 typedef uint8_t length_t;
297 /*+ Conversion of km/hr to speed_t. +*/
298 #define kph_to_speed(xxx) (speed_t)(xxx)
300 /*+ Conversion of speed_t to km/hr. +*/
301 #define speed_to_kph(xxx) (int)(xxx)
303 /*+ Conversion of tonnes to weight_t. +*/
304 #define tonnes_to_weight(xxx) (weight_t)((xxx)*5)
306 /*+ Conversion of weight_t to tonnes. +*/
307 #define weight_to_tonnes(xxx) ((double)(xxx)/5.0)
309 /*+ Conversion of metres to height_t. +*/
310 #define metres_to_height(xxx) (height_t)((xxx)*10)
312 /*+ Conversion of height_t to metres. +*/
313 #define height_to_metres(xxx) ((double)(xxx)/10.0)
315 /*+ Conversion of metres to width_t. +*/
316 #define metres_to_width(xxx) (width_t)((xxx)*10)
318 /*+ Conversion of width_t to metres. +*/
319 #define width_to_metres(xxx) ((double)(xxx)/10.0)
321 /*+ Conversion of metres to length_t. +*/
322 #define metres_to_length(xxx) (length_t)((xxx)*10)
324 /*+ Conversion of length_t to metres. +*/
325 #define length_to_metres(xxx) ((double)(xxx)/10.0)
328 /* Data structures */
330 typedef struct _Node Node;
332 typedef struct _Nodes Nodes;
334 typedef struct _Segment Segment;
336 typedef struct _Segments Segments;
338 typedef struct _Way Way;
340 typedef struct _Ways Ways;
345 Highway HighwayType(const char *highway);
346 Transport TransportType(const char *transport);
347 Property PropertyType(const char *property);
349 const char *HighwayName(Highway highway);
350 const char *TransportName(Transport transport);
351 const char *PropertyName(Property property);
353 const char *AllowedNameList(allow_t allowed);
354 const char *PropertiesNameList(wayprop_t properties);
356 const char *HighwayList(void);
357 const char *TransportList(void);
358 const char *PropertyList(void);