]> git.mxchange.org Git - simgear.git/blob - simgear/route/waypoint.hxx
Christian M. says it's bad to chain one constructor call from another.
[simgear.git] / simgear / route / waypoint.hxx
1 /** 
2  * \file waypoint.hxx
3  * Provides a class to manage waypoints
4  */
5
6 // Written by Curtis Olson, started September 2000.
7 //
8 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24 // $Id$
25
26
27 #ifndef _WAYPOINT_HXX
28 #define _WAYPOINT_HXX
29
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35
36 #include <simgear/compiler.h>
37
38 #include STL_STRING
39
40 SG_USING_STD(string);
41
42
43 /**
44  * A class to manage waypoints.
45  */
46
47 class SGWayPoint {
48
49 public:
50
51     /**
52      * Waypoint mode.
53      * <li> WGS84 requests all bearing and distance math be done assuming a
54      *      WGS84 ellipsoid world.  This is the most expensive computationally,
55      *      but also the most accurate.
56      * <li> SPHERICAL requests all bearing and distance math be done assuming
57      *      the world is a perfect sphere.  This is less compuntationally
58      *      expensive than using wgs84 math and still a fairly good
59      *      approximation of the real world, especially over shorter distances.
60      * <li> CARTESIAN requests all math be done assuming the coordinates specify
61      *      position in a Z = up world.
62      */
63     enum modetype { 
64         WGS84 = 0,
65         SPHERICAL = 1,
66         CARTESIAN = 2
67     };
68
69 private:
70
71     modetype mode;
72
73     double target_lon;
74     double target_lat;
75     double target_alt;
76     double distance;
77
78     string id;
79
80 public:
81
82     /**
83      * Construct a waypoint
84      * @param lon destination longitude
85      * @param lat destination latitude
86      * @param alt target altitude
87      * @param mode type of coordinates/math to use
88      * @param s waypoint identifier
89      */
90     SGWayPoint( const double lon = 0.0, const double lat = 0.0,
91                 const double alt = 0.0, const modetype m = WGS84,
92                 const string s = "" );
93
94     /** Destructor */
95     ~SGWayPoint();
96
97     /**
98      * Calculate course and distances.  For WGS84 and SPHERICAL
99      * coordinates lat, lon, and course are in degrees, alt and
100      * distance are in meters.  For CARTESIAN coordinates x = lon, y =
101      * lat.  Course is in degrees and distance is in what ever units x
102      * and y are in.
103      * @param cur_lon (in) current longitude
104      * @param cur_lat (in) current latitude
105      * @param cur_alt (in) current altitude
106      * @param course (out) heading from current location to this waypoint
107      * @param distance (out) distance from current location to this waypoint
108      */
109     void CourseAndDistance( const double cur_lon, const double cur_lat,
110                             const double cur_alt,
111                             double *course, double *distance ) const;
112
113     /**
114      * Calculate course and distances between a specified starting waypoint
115      * and this waypoint.
116      * @param wp (in) original waypoint
117      * @param course (out) heading from current location to this waypoint
118      * @param distance (out) distance from current location to this waypoint
119      */
120     void CourseAndDistance( const SGWayPoint &wp,
121                             double *course, double *distance ) const;
122
123     /** @return waypoint mode */
124     inline modetype get_mode() const { return mode; }
125
126     /** @return waypoint longitude */
127     inline double get_target_lon() const { return target_lon; }
128
129     /** @return waypoint latitude */
130     inline double get_target_lat() const { return target_lat; }
131
132     /** @return waypoint altitude */
133     inline double get_target_alt() const { return target_alt; }
134
135     /**
136      * This value is not calculated by this class.  It is simply a
137      * placeholder for the user to stash a distance value.  This is useful
138      * when you stack waypoints together into a route.  You can calculate the
139      * distance from the previous waypoint once and save it here.  Adding up
140      * all the distances here plus the distance to the first waypoint gives you
141      * the total route length.  Note, you must update this value yourself, this
142      * is for your convenience only.
143      * @return waypoint distance holder (what ever the user has stashed here)
144      */
145     inline double get_distance() const { return distance; }
146
147     /**
148      * Set the waypoint distance value to a value of our choice.
149      * @param d distance 
150      */
151     inline void set_distance( double d ) { distance = d; }
152
153     /** @return waypoint id */
154     inline string get_id() const { return id; }
155
156 };
157
158
159 #endif // _WAYPOINT_HXX