Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/segments.c
Parent Directory
|
Revision Log
Revision 109 -
(show annotations)
(download)
(as text)
Sat Feb 7 15:56:08 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 3449 byte(s)
Sat Feb 7 15:56:08 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 3449 byte(s)
Split the extended data types from the normal data types.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/segments.c,v 1.31 2009-02-07 15:56:07 amb Exp $ |
3 | |
4 | Segment data type functions. |
5 | ******************/ /****************** |
6 | Written by Andrew M. Bishop |
7 | |
8 | This file Copyright 2008,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 | #include <assert.h> |
16 | #include <math.h> |
17 | #include <string.h> |
18 | #include <stdlib.h> |
19 | |
20 | #include "types.h" |
21 | #include "functions.h" |
22 | #include "nodes.h" |
23 | #include "segments.h" |
24 | #include "ways.h" |
25 | #include "profiles.h" |
26 | |
27 | |
28 | /*++++++++++++++++++++++++++++++++++++++ |
29 | Load in a segment list from a file. |
30 | |
31 | Segments* SaveSegmentList Returns the segment list that has just been loaded. |
32 | |
33 | const char *filename The name of the file to load. |
34 | ++++++++++++++++++++++++++++++++++++++*/ |
35 | |
36 | Segments *LoadSegmentList(const char *filename) |
37 | { |
38 | void *data; |
39 | Segments *segments; |
40 | |
41 | segments=(Segments*)malloc(sizeof(Segments)); |
42 | |
43 | data=MapFile(filename); |
44 | |
45 | if(!data) |
46 | return(NULL); |
47 | |
48 | /* Copy the Segments structure from the loaded data */ |
49 | |
50 | *segments=*((Segments*)data); |
51 | |
52 | /* Adjust the pointers in the Segments structure. */ |
53 | |
54 | segments->data=data; |
55 | segments->segments=(Segment*)(data+(off_t)segments->segments); |
56 | |
57 | return(segments); |
58 | } |
59 | |
60 | |
61 | /*++++++++++++++++++++++++++++++++++++++ |
62 | Find the next segment with a particular starting node. |
63 | |
64 | Segment *NextSegment Returns a pointer to the next segment with the same id. |
65 | |
66 | Segments* segments The set of segments to process. |
67 | |
68 | Segment *segment The current segment. |
69 | ++++++++++++++++++++++++++++++++++++++*/ |
70 | |
71 | Segment *NextSegment(Segments* segments,Segment *segment,index_t node) |
72 | { |
73 | index_t next; |
74 | |
75 | if(NODE(segment->node1)==node) |
76 | next=segment->next1; |
77 | else |
78 | next=segment->next2; |
79 | |
80 | if(next==~0) |
81 | return(NULL); |
82 | else |
83 | return(LookupSegment(segments,next)); |
84 | } |
85 | |
86 | |
87 | /*++++++++++++++++++++++++++++++++++++++ |
88 | Calculate the distance between two locations. |
89 | |
90 | float Distance Returns the distance between the locations. |
91 | |
92 | float lat1 The latitude of the first location. |
93 | |
94 | float lon1 The longitude of the first location. |
95 | |
96 | float lat2 The latitude of the second location. |
97 | |
98 | float lon2 The longitude of the second location. |
99 | ++++++++++++++++++++++++++++++++++++++*/ |
100 | |
101 | float Distance(float lat1,float lon1,float lat2,float lon2) |
102 | { |
103 | double radiant = M_PI / 180; |
104 | |
105 | double dlon = radiant * (lon1 - lon2); |
106 | double dlat = radiant * (lat1 - lat2); |
107 | |
108 | double a1,a2,a,sa,c,d; |
109 | |
110 | if(dlon==0 && dlat==0) |
111 | return 0; |
112 | |
113 | a1 = sin (dlat / 2); |
114 | a2 = sin (dlon / 2); |
115 | a = (a1 * a1) + cos (lat1 * radiant) * cos (lat2 * radiant) * a2 * a2; |
116 | sa = sqrt (a); |
117 | if (sa <= 1.0) |
118 | {c = 2 * asin (sa);} |
119 | else |
120 | {c = 2 * asin (1.0);} |
121 | d = 6378.137 * c; |
122 | |
123 | return d; |
124 | } |
125 | |
126 | |
127 | /*++++++++++++++++++++++++++++++++++++++ |
128 | Calculate the duration of segment. |
129 | |
130 | duration_t Duration Returns the duration of travel between the nodes. |
131 | |
132 | Segment *segment The segment to traverse. |
133 | |
134 | Way *way The way that the segment belongs to. |
135 | |
136 | Profile *profile The profile of the transport being used. |
137 | ++++++++++++++++++++++++++++++++++++++*/ |
138 | |
139 | duration_t Duration(Segment *segment,Way *way,Profile *profile) |
140 | { |
141 | speed_t speed=profile->speed[HIGHWAY(way->type)]; |
142 | distance_t distance=DISTANCE(segment->distance); |
143 | |
144 | return distance_speed_to_duration(distance,speed); |
145 | } |
Properties
Name | Value |
---|---|
cvs:description | Segment data type. |