Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/segments.c
Parent Directory
|
Revision Log
Revision 449 -
(hide annotations)
(download)
(as text)
Mon Jul 12 17:59:42 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 4353 byte(s)
Mon Jul 12 17:59:42 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 4353 byte(s)
Create a files.h header and put some of the most heavily used files.c functions into it and make them inline.
1 | amb | 2 | /*************************************** |
2 | amb | 449 | $Header: /home/amb/CVS/routino/src/segments.c,v 1.46 2010-07-12 17:59:41 amb Exp $ |
3 | amb | 2 | |
4 | Segment data type functions. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 2 | ******************/ /****************** |
8 | amb | 328 | This file Copyright 2008-2010 Andrew M. Bishop |
9 | amb | 2 | |
10 | amb | 151 | 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 | amb | 2 | ***************************************/ |
23 | |||
24 | |||
25 | amb | 214 | #include <sys/types.h> |
26 | amb | 2 | #include <stdlib.h> |
27 | |||
28 | amb | 109 | #include "types.h" |
29 | amb | 39 | #include "nodes.h" |
30 | amb | 26 | #include "segments.h" |
31 | amb | 109 | #include "ways.h" |
32 | amb | 449 | |
33 | #include "files.h" | ||
34 | amb | 109 | #include "profiles.h" |
35 | amb | 2 | |
36 | |||
37 | amb | 23 | /*++++++++++++++++++++++++++++++++++++++ |
38 | amb | 2 | Load in a segment list from a file. |
39 | |||
40 | amb | 228 | Segments* LoadSegmentList Returns the segment list that has just been loaded. |
41 | amb | 23 | |
42 | amb | 2 | const char *filename The name of the file to load. |
43 | ++++++++++++++++++++++++++++++++++++++*/ | ||
44 | |||
45 | amb | 23 | Segments *LoadSegmentList(const char *filename) |
46 | amb | 2 | { |
47 | amb | 88 | void *data; |
48 | Segments *segments; | ||
49 | |||
50 | segments=(Segments*)malloc(sizeof(Segments)); | ||
51 | |||
52 | data=MapFile(filename); | ||
53 | |||
54 | /* Copy the Segments structure from the loaded data */ | ||
55 | |||
56 | *segments=*((Segments*)data); | ||
57 | |||
58 | /* Adjust the pointers in the Segments structure. */ | ||
59 | |||
60 | amb | 104 | segments->data=data; |
61 | amb | 385 | segments->segments=(Segment*)(data+sizeof(Segments)); |
62 | amb | 88 | |
63 | return(segments); | ||
64 | amb | 2 | } |
65 | |||
66 | |||
67 | /*++++++++++++++++++++++++++++++++++++++ | ||
68 | Find the next segment with a particular starting node. | ||
69 | |||
70 | amb | 88 | Segment *NextSegment Returns a pointer to the next segment with the same id. |
71 | amb | 2 | |
72 | amb | 23 | Segments* segments The set of segments to process. |
73 | |||
74 | amb | 2 | Segment *segment The current segment. |
75 | amb | 228 | |
76 | index_t node The current node. | ||
77 | amb | 2 | ++++++++++++++++++++++++++++++++++++++*/ |
78 | |||
79 | amb | 104 | Segment *NextSegment(Segments* segments,Segment *segment,index_t node) |
80 | amb | 2 | { |
81 | amb | 208 | if(segment->node1==node) |
82 | amb | 128 | { |
83 | segment++; | ||
84 | amb | 214 | if((segment-segments->segments)>=segments->number || segment->node1!=node) |
85 | amb | 128 | return(NULL); |
86 | else | ||
87 | return(segment); | ||
88 | } | ||
89 | amb | 104 | else |
90 | amb | 128 | { |
91 | amb | 176 | if(segment->next2==NO_NODE) |
92 | amb | 128 | return(NULL); |
93 | else | ||
94 | return(LookupSegment(segments,segment->next2)); | ||
95 | } | ||
96 | amb | 89 | } |
97 | amb | 88 | |
98 | |||
99 | amb | 2 | /*++++++++++++++++++++++++++++++++++++++ |
100 | amb | 99 | Calculate the distance between two locations. |
101 | |||
102 | amb | 114 | distance_t Distance Returns the distance between the locations. |
103 | amb | 99 | |
104 | amb | 219 | double lat1 The latitude of the first location. |
105 | amb | 99 | |
106 | amb | 219 | double lon1 The longitude of the first location. |
107 | amb | 99 | |
108 | amb | 219 | double lat2 The latitude of the second location. |
109 | amb | 99 | |
110 | amb | 219 | double lon2 The longitude of the second location. |
111 | amb | 99 | ++++++++++++++++++++++++++++++++++++++*/ |
112 | |||
113 | amb | 219 | distance_t Distance(double lat1,double lon1,double lat2,double lon2) |
114 | amb | 99 | { |
115 | amb | 219 | double dlon = lon1 - lon2; |
116 | double dlat = lat1 - lat2; | ||
117 | amb | 99 | |
118 | amb | 219 | double a1,a2,a,sa,c,d; |
119 | amb | 99 | |
120 | if(dlon==0 && dlat==0) | ||
121 | return 0; | ||
122 | |||
123 | amb | 219 | a1 = sin (dlat / 2); |
124 | a2 = sin (dlon / 2); | ||
125 | a = (a1 * a1) + cos (lat1) * cos (lat2) * a2 * a2; | ||
126 | sa = sqrt (a); | ||
127 | amb | 99 | if (sa <= 1.0) |
128 | amb | 219 | {c = 2 * asin (sa);} |
129 | amb | 99 | else |
130 | amb | 219 | {c = 2 * asin (1.0);} |
131 | amb | 99 | d = 6378.137 * c; |
132 | |||
133 | amb | 114 | return km_to_distance(d); |
134 | amb | 99 | } |
135 | |||
136 | |||
137 | /*++++++++++++++++++++++++++++++++++++++ | ||
138 | amb | 63 | Calculate the duration of segment. |
139 | |||
140 | duration_t Duration Returns the duration of travel between the nodes. | ||
141 | |||
142 | Segment *segment The segment to traverse. | ||
143 | |||
144 | Way *way The way that the segment belongs to. | ||
145 | |||
146 | amb | 82 | Profile *profile The profile of the transport being used. |
147 | amb | 63 | ++++++++++++++++++++++++++++++++++++++*/ |
148 | |||
149 | amb | 82 | duration_t Duration(Segment *segment,Way *way,Profile *profile) |
150 | amb | 63 | { |
151 | amb | 137 | speed_t speed1=way->speed; |
152 | speed_t speed2=profile->speed[HIGHWAY(way->type)]; | ||
153 | amb | 90 | distance_t distance=DISTANCE(segment->distance); |
154 | amb | 63 | |
155 | amb | 137 | if(speed1==0) |
156 | { | ||
157 | if(speed2==0) | ||
158 | return(hours_to_duration(10)); | ||
159 | else | ||
160 | return distance_speed_to_duration(distance,speed2); | ||
161 | } | ||
162 | else /* if(speed1!=0) */ | ||
163 | { | ||
164 | if(speed2==0) | ||
165 | return distance_speed_to_duration(distance,speed1); | ||
166 | else if(speed1<=speed2) | ||
167 | return distance_speed_to_duration(distance,speed1); | ||
168 | else | ||
169 | return distance_speed_to_duration(distance,speed2); | ||
170 | } | ||
171 | amb | 63 | } |
Properties
Name | Value |
---|---|
cvs:description | Segment data type. |