Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/segments.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations) (download) (as text)
Tue Feb 24 19:59:52 2009 UTC (16 years, 1 month 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 /***************************************
2 $Header: /home/amb/CVS/routino/src/segments.c,v 1.35 2009-02-24 19:59:36 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 if(NODE(segment->node1)==node)
74 {
75 segment++;
76 if(NODE(segment->node1)!=node || (segment-segments->segments)>=segments->number)
77 return(NULL);
78 else
79 return(segment);
80 }
81 else
82 {
83 if(segment->next2==~0)
84 return(NULL);
85 else
86 return(LookupSegment(segments,segment->next2));
87 }
88 }
89
90
91 /*++++++++++++++++++++++++++++++++++++++
92 Calculate the distance between two locations.
93
94 distance_t Distance Returns the distance between the locations.
95
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 distance_t Distance(float lat1,float lon1,float lat2,float lon2)
106 {
107 float dlon = lon1 - lon2;
108 float dlat = lat1 - lat2;
109
110 float a1,a2,a,sa,c,d;
111
112 if(dlon==0 && dlat==0)
113 return 0;
114
115 a1 = sinf (dlat / 2);
116 a2 = sinf (dlon / 2);
117 a = (a1 * a1) + cosf (lat1) * cosf (lat2) * a2 * a2;
118 sa = sqrtf (a);
119 if (sa <= 1.0)
120 {c = 2 * asinf (sa);}
121 else
122 {c = 2 * asinf (1.0);}
123 d = 6378.137 * c;
124
125 return km_to_distance(d);
126 }
127
128
129 /*++++++++++++++++++++++++++++++++++++++
130 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 Profile *profile The profile of the transport being used.
139 ++++++++++++++++++++++++++++++++++++++*/
140
141 duration_t Duration(Segment *segment,Way *way,Profile *profile)
142 {
143 speed_t speed=profile->speed[HIGHWAY(way->type)];
144 distance_t distance=DISTANCE(segment->distance);
145
146 return distance_speed_to_duration(distance,speed);
147 }

Properties

Name Value
cvs:description Segment data type.