Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/segments.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (hide annotations) (download) (as text)
Tue Feb 24 19:59:52 2009 UTC (16 years ago) by amb
File MIME type: text/x-csrc
File size: 3543 byte(s)
Remove segment->next1 since it always points at the next segment or nowhere.

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

Properties

Name Value
cvs:description Segment data type.