Imported Upstream version 1.4.1
[routino] / src / segments.h
1 /***************************************
2  $Header: /home/amb/routino/src/RCS/segments.h,v 1.34 2009/11/14 19:39:20 amb Exp $
3
4  A header file for the segments.
5
6  Part of the Routino routing software.
7  ******************/ /******************
8  This file Copyright 2008,2009 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 #include "profiles.h"
32
33
34 /* Data structures */
35
36
37 /*+ A structure containing a single segment. +*/
38 struct _Segment
39 {
40  index_t    node1;              /*+ The index of the starting node. +*/
41  index_t    node2;              /*+ The index of the finishing node. +*/
42
43  index_t    next2;              /*+ The index of the next segment sharing node2. +*/
44
45  index_t    way;                /*+ The index of the way associated with the segment. +*/
46
47  distance_t distance;           /*+ The distance between the nodes. +*/
48 };
49
50
51 /*+ A structure containing a set of segments (mmap format). +*/
52 struct _Segments
53 {
54  uint32_t  number;              /*+ How many segments in total? +*/
55  uint32_t  snumber;             /*+ How many super-segments? +*/
56  uint32_t  nnumber;             /*+ How many normal segments? +*/
57
58  Segment  *segments;            /*+ An array of segments. +*/
59
60  void     *data;                /*+ The memory mapped data. +*/
61 };
62
63
64 /* Macros */
65
66
67 /*+ Return a segment pointer given a set of segments and an index. +*/
68 #define LookupSegment(xxx,yyy) (&(xxx)->segments[yyy])
69
70 /*+ Return a segment index given a set of segments and a pointer. +*/
71 #define IndexSegment(xxx,yyy)  ((yyy)-&(xxx)->segments[0])
72
73 /*+ Return true if this is a normal segment. +*/
74 #define IsNormalSegment(xxx)   (((xxx)->distance)&SEGMENT_NORMAL)
75
76 /*+ Return true if this is a super-segment. +*/
77 #define IsSuperSegment(xxx)    (((xxx)->distance)&SEGMENT_SUPER)
78
79 /*+ Return true if the segment is oneway towards the specified node. +*/
80 #define IsOnewayTo(xxx,yyy)    ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
81
82 /*+ Return true if the segment is oneway from the specified node. +*/
83 #define IsOnewayFrom(xxx,yyy)  ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
84
85 /*+ Return the other node in the segment that is not the specified node. +*/
86 #define OtherNode(xxx,yyy)     ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1)
87
88
89 /* Functions */
90
91
92 Segments *LoadSegmentList(const char *filename);
93
94 Segment *NextSegment(Segments* segments,Segment *segment,index_t node);
95
96 distance_t Distance(double lat1,double lon1,double lat2,double lon2);
97
98 duration_t Duration(Segment *segment,Way *way,Profile *profile);
99
100
101 #endif /* SEGMENTS_H */