Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/segments.h
Parent Directory
|
Revision Log
Revision 54 -
(hide annotations)
(download)
(as text)
Sun Jan 18 16:04:09 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4156 byte(s)
Sun Jan 18 16:04:09 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4156 byte(s)
Added Super-Ways and allow user to select method of transport.
1 | amb | 24 | /*************************************** |
2 | amb | 54 | $Header: /home/amb/CVS/routino/src/segments.h,v 1.8 2009-01-18 16:03:45 amb Exp $ |
3 | amb | 24 | |
4 | A header file for the segments. | ||
5 | ******************/ /****************** | ||
6 | Written by Andrew M. Bishop | ||
7 | |||
8 | This file Copyright 2009 Andrew M. Bishop | ||
9 | It may be distributed under the GNU Public License, version 2, or | ||
10 | any higher version. See section COPYING of the GNU Public license | ||
11 | for conditions under which this file may be redistributed. | ||
12 | ***************************************/ | ||
13 | |||
14 | |||
15 | #ifndef SEGMENTS_H | ||
16 | #define SEGMENTS_H /*+ To stop multiple inclusions. +*/ | ||
17 | |||
18 | #include <stdint.h> | ||
19 | |||
20 | amb | 26 | #include "nodes.h" |
21 | #include "ways.h" | ||
22 | amb | 24 | |
23 | amb | 26 | |
24 | amb | 24 | /* Constants */ |
25 | |||
26 | |||
27 | #if 1 /* set to 0 to use a flat array, 1 for indexed. */ | ||
28 | |||
29 | /*+ The number of bins for segments. +*/ | ||
30 | #define NBINS_SEGMENTS 2048 | ||
31 | |||
32 | #else | ||
33 | |||
34 | #undef NBINS_SEGMENTS | ||
35 | |||
36 | #endif | ||
37 | |||
38 | amb | 27 | /*+ The array size increment for segments. +*/ |
39 | #define INCREMENT_SEGMENTS 1024*1024 | ||
40 | amb | 24 | |
41 | amb | 27 | |
42 | amb | 24 | /* Simple Types */ |
43 | |||
44 | |||
45 | /*+ A short distance, measured in metres (up to ~65.5km). +*/ | ||
46 | typedef uint16_t distance_short_t; | ||
47 | |||
48 | amb | 31 | /*+ A short duration, measured in 1/10th seconds (up to ~110 minutes). +*/ |
49 | amb | 24 | typedef uint16_t duration_short_t; |
50 | |||
51 | amb | 39 | /*+ An invalid short distance +*/ |
52 | #define INVALID_SHORT_DISTANCE (distance_short_t)(~0) | ||
53 | amb | 24 | |
54 | amb | 39 | /*+ An invalid duration +*/ |
55 | #define INVALID_SHORT_DURATION (duration_short_t)(~0) | ||
56 | |||
57 | |||
58 | amb | 24 | /*+ A long distance, measured in metres. +*/ |
59 | typedef uint32_t distance_t; | ||
60 | |||
61 | amb | 39 | /*+ A duration, measured in 1/10th seconds. +*/ |
62 | typedef uint32_t duration_t; | ||
63 | |||
64 | |||
65 | /*+ An invalid distance +*/ | ||
66 | #define INVALID_DISTANCE (distance_t)(~0) | ||
67 | |||
68 | /*+ An invalid duration +*/ | ||
69 | #define INVALID_DURATION (duration_t)(~0) | ||
70 | |||
71 | |||
72 | amb | 24 | /*+ Conversion from distance_t to kilometres. +*/ |
73 | #define distance_to_km(xx) ((double)(xx)/1000.0) | ||
74 | |||
75 | /*+ Conversion from metres to distance_t. +*/ | ||
76 | #define km_to_distance(xx) ((distance_t)((double)(xx)*1000.0)) | ||
77 | |||
78 | /*+ Conversion from duration_t to minutes. +*/ | ||
79 | amb | 31 | #define duration_to_minutes(xx) ((double)(xx)/600.0) |
80 | amb | 24 | |
81 | /*+ Conversion from duration_t to hours. +*/ | ||
82 | amb | 31 | #define duration_to_hours(xx) ((double)(xx)/36000.0) |
83 | amb | 24 | |
84 | /*+ Conversion from hours to duration_t. +*/ | ||
85 | amb | 31 | #define hours_to_duration(xx) ((duration_t)((double)(xx)*36000.0)) |
86 | amb | 24 | |
87 | |||
88 | /* Data structures */ | ||
89 | |||
90 | |||
91 | /*+ A structure containing a single segment. +*/ | ||
92 | typedef struct _Segment | ||
93 | { | ||
94 | node_t node1; /*+ The starting node. +*/ | ||
95 | node_t node2; /*+ The finishing node. +*/ | ||
96 | way_t way; /*+ The way associated with the segment. +*/ | ||
97 | distance_short_t distance; /*+ The distance between the nodes. +*/ | ||
98 | duration_short_t duration; /*+ The time duration to travel between the nodes. +*/ | ||
99 | } | ||
100 | Segment; | ||
101 | |||
102 | /*+ A structure containing a set of segments (mmap format). +*/ | ||
103 | typedef struct _Segments | ||
104 | { | ||
105 | amb | 26 | uint32_t number; /*+ How many entries are used? +*/ |
106 | amb | 24 | #ifdef NBINS_SEGMENTS |
107 | amb | 26 | uint32_t offset[NBINS_SEGMENTS+1]; /*+ An offset to the first entry in each bin. +*/ |
108 | amb | 24 | #endif |
109 | Segment segments[1]; /*+ An array of segments whose size is not limited to 1 | ||
110 | (i.e. may overflow the end of this structure). +*/ | ||
111 | } | ||
112 | Segments; | ||
113 | |||
114 | /*+ A structure containing a set of segments (memory format). +*/ | ||
115 | typedef struct _SegmentsMem | ||
116 | { | ||
117 | uint32_t alloced; /*+ How many entries are allocated? +*/ | ||
118 | uint32_t number; /*+ How many entries are used? +*/ | ||
119 | uint32_t sorted; /*+ Is the data sorted and therefore searchable? +*/ | ||
120 | |||
121 | Segments *segments; /*+ The real data +*/ | ||
122 | } | ||
123 | SegmentsMem; | ||
124 | |||
125 | |||
126 | amb | 26 | /* Functions in segments.c */ |
127 | amb | 24 | |
128 | |||
129 | SegmentsMem *NewSegmentList(void); | ||
130 | |||
131 | Segments *LoadSegmentList(const char *filename); | ||
132 | Segments *SaveSegmentList(SegmentsMem *segments,const char *filename); | ||
133 | |||
134 | Segment *FindFirstSegment(Segments *segments,node_t node); | ||
135 | Segment *FindNextSegment(Segments *segments,Segment *segment); | ||
136 | |||
137 | amb | 31 | Segment *AppendSegment(SegmentsMem *segments,node_t node1,node_t node2,way_t way); |
138 | amb | 24 | |
139 | void SortSegmentList(SegmentsMem *segments); | ||
140 | |||
141 | amb | 39 | void RemoveBadSegments(SegmentsMem *segments); |
142 | |||
143 | amb | 24 | void FixupSegmentLengths(SegmentsMem *segments,Nodes *nodes,Ways *ways); |
144 | |||
145 | distance_t Distance(Node *node1,Node *node2); | ||
146 | |||
147 | amb | 32 | #define LookupSegment(xxx,yyy) (&xxx->segments[yyy]) |
148 | amb | 24 | |
149 | amb | 32 | |
150 | amb | 24 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |