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 1168 - (show annotations) (download) (as text)
Wed Nov 21 09:20:57 2012 UTC (12 years, 4 months ago) by amb
File MIME type: text/x-chdr
File size: 7393 byte(s)
Revert r1164 - some super-segments are longer than 65535 metres even if no
individual segment is.

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

Properties

Name Value
cvs:description Header file for segments.