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