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/segments.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1553 - (show annotations) (download) (as text)
Sun Apr 27 15:58:52 2014 UTC (10 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 7793 byte(s)
Fix bug with particular arrangement of a fake node (waypoint in middle of
segment) and a roundabout.  The FindFinishRoutes() function was invalidly
allowing a U-turn which the later parts of the route calculation didn't and
therefore failed to find a route.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/segments.h,v 1.38 2010-12-21 17:18:41 amb Exp $
3
4 A header file for the segments.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2014 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 SEGMENTS_H
26 #define SEGMENTS_H /*+ To stop multiple inclusions. +*/
27
28 #include <stdint.h>
29
30 #include "types.h"
31
32 #include "cache.h"
33 #include "files.h"
34 #include "profiles.h"
35
36
37 /* Data structures */
38
39
40 /*+ A structure containing a single segment. +*/
41 struct _Segment
42 {
43 index_t node1; /*+ The index of the starting node. +*/
44 index_t node2; /*+ The index of the finishing node. +*/
45
46 index_t next2; /*+ The index of the next segment sharing node2. +*/
47
48 index_t way; /*+ The index of the way associated with the segment. +*/
49
50 distance_t distance; /*+ The distance between the nodes. +*/
51 };
52
53
54 /*+ A structure containing the header from the file. +*/
55 typedef struct _SegmentsFile
56 {
57 index_t number; /*+ The number of segments in total. +*/
58 index_t snumber; /*+ The number of super-segments. +*/
59 index_t nnumber; /*+ The number of normal segments. +*/
60 }
61 SegmentsFile;
62
63
64 /*+ A structure containing a set of segments (and pointers to mmap file). +*/
65 struct _Segments
66 {
67 SegmentsFile file; /*+ The header data from the file. +*/
68
69 #if !SLIM
70
71 void *data; /*+ The memory mapped data. +*/
72
73 Segment *segments; /*+ An array of segments. +*/
74
75 #else
76
77 int fd; /*+ The file descriptor for the file. +*/
78
79 Segment cached[4]; /*+ Three cached segments read from the file in slim mode. +*/
80 index_t incache[4]; /*+ The indexes of the cached segments. +*/
81
82 SegmentCache *cache; /*+ A RAM cache of segments read from the file. +*/
83
84 #endif
85 };
86
87
88 /* Functions in segments.c */
89
90 Segments *LoadSegmentList(const char *filename);
91
92 void DestroySegmentList(Segments *segments);
93
94 index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile);
95
96 distance_t Distance(double lat1,double lon1,double lat2,double lon2);
97
98 duration_t Duration(Segment *segmentp,Way *wayp,Profile *profile);
99
100 double TurnAngle(Nodes *nodes,Segment *segment1p,Segment *segment2p,index_t node);
101 double BearingAngle(Nodes *nodes,Segment *segmentp,index_t node);
102
103
104 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node);
105
106
107 /* Macros and inline functions */
108
109 /*+ Return true if this is a normal segment. +*/
110 #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL)
111
112 /*+ Return true if this is a super-segment. +*/
113 #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER)
114
115 /*+ Return true if the segment is oneway. +*/
116 #define IsOneway(xxx) ((xxx)->distance&(ONEWAY_2TO1|ONEWAY_1TO2))
117
118 /*+ Return true if the segment is oneway towards the specified node. +*/
119 #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
120
121 /*+ Return true if the segment is oneway from the specified node. +*/
122 #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
123
124 /*+ Return the other node in the segment that is not the specified node. +*/
125 #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1)
126
127
128 #if !SLIM
129
130 /*+ Return a segment pointer given a set of segments and an index. +*/
131 #define LookupSegment(xxx,yyy,ppp) (&(xxx)->segments[yyy])
132
133 /*+ Return a segment index given a set of segments and a pointer. +*/
134 #define IndexSegment(xxx,yyy) (index_t)((yyy)-&(xxx)->segments[0])
135
136
137 /*++++++++++++++++++++++++++++++++++++++
138 Find the next segment with a particular starting node.
139
140 Segment *NextSegment Returns a pointer to the next segment.
141
142 Segments *segments The set of segments to use.
143
144 Segment *segmentp The current segment.
145
146 index_t node The wanted node.
147 ++++++++++++++++++++++++++++++++++++++*/
148
149 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node)
150 {
151 if(segmentp->node1==node)
152 {
153 segmentp++;
154
155 if(IndexSegment(segments,segmentp)>=segments->file.number || segmentp->node1!=node)
156 return(NULL);
157 else
158 return(segmentp);
159 }
160 else
161 {
162 if(segmentp->next2==NO_SEGMENT)
163 return(NULL);
164 else
165 return(LookupSegment(segments,segmentp->next2,1));
166 }
167 }
168
169 #else
170
171 /* Prototypes */
172
173 static inline Segment *LookupSegment(Segments *segments,index_t index,int position);
174
175 static inline index_t IndexSegment(Segments *segments,Segment *segmentp);
176
177 CACHE_NEWCACHE_PROTO(Segment)
178 CACHE_DELETECACHE_PROTO(Segment)
179 CACHE_FETCHCACHE_PROTO(Segment)
180 CACHE_INVALIDATECACHE_PROTO(Segment)
181
182
183 /* Inline functions */
184
185 CACHE_STRUCTURE(Segment)
186 CACHE_NEWCACHE(Segment)
187 CACHE_DELETECACHE(Segment)
188 CACHE_FETCHCACHE(Segment)
189 CACHE_INVALIDATECACHE(Segment)
190
191
192 /*++++++++++++++++++++++++++++++++++++++
193 Find the Segment information for a particular segment.
194
195 Segment *LookupSegment Returns a pointer to the cached segment information.
196
197 Segments *segments The set of segments to use.
198
199 index_t index The index of the segment.
200
201 int position The position in the cache to store the value.
202 ++++++++++++++++++++++++++++++++++++++*/
203
204 static inline Segment *LookupSegment(Segments *segments,index_t index,int position)
205 {
206 segments->cached[position-1]=*FetchCachedSegment(segments->cache,index,segments->fd,sizeof(SegmentsFile));
207
208 segments->incache[position-1]=index;
209
210 return(&segments->cached[position-1]);
211 }
212
213
214 /*++++++++++++++++++++++++++++++++++++++
215 Find the segment index for a particular segment pointer.
216
217 index_t IndexSegment Returns the index of the segment in the list.
218
219 Segments *segments The set of segments to use.
220
221 Segment *segmentp The segment whose index is to be found.
222 ++++++++++++++++++++++++++++++++++++++*/
223
224 static inline index_t IndexSegment(Segments *segments,Segment *segmentp)
225 {
226 int position1=segmentp-&segments->cached[0];
227
228 return(segments->incache[position1]);
229 }
230
231
232 /*++++++++++++++++++++++++++++++++++++++
233 Find the next segment with a particular starting node.
234
235 Segment *NextSegment Returns a pointer to the next segment.
236
237 Segments *segments The set of segments to use.
238
239 Segment *segmentp The current segment.
240
241 index_t node The wanted node.
242 ++++++++++++++++++++++++++++++++++++++*/
243
244 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node)
245 {
246 int position=segmentp-&segments->cached[-1];
247
248 if(segmentp->node1==node)
249 {
250 index_t index=IndexSegment(segments,segmentp);
251
252 index++;
253
254 if(index>=segments->file.number)
255 return(NULL);
256
257 segmentp=LookupSegment(segments,index,position);
258
259 if(segmentp->node1!=node)
260 return(NULL);
261 else
262 return(segmentp);
263 }
264 else
265 {
266 if(segmentp->next2==NO_SEGMENT)
267 return(NULL);
268 else
269 return(LookupSegment(segments,segmentp->next2,position));
270 }
271 }
272
273 #endif
274
275
276 #endif /* SEGMENTS_H */

Properties

Name Value
cvs:description Header file for segments.