]> git.mxchange.org Git - simgear.git/blob - simgear/route/waypoint.hxx
Fix bad interaction between CourseAndDistance overloads and use of implicit
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 <simgear/math/SGMath.hxx>
39 #include <simgear/math/SGGeod.hxx>
40
41 #include <string>
42
43
44 /**
45  * A class to manage waypoints.
46  */
47
48 class SGWayPoint {
49
50 public:
51
52     /**
53      * Waypoint mode.
54      * <li> WGS84 requests all bearing and distance math be done assuming a
55      *      WGS84 ellipsoid world.  This is the most expensive computationally,
56      *      but also the most accurate.
57      * <li> SPHERICAL requests all bearing and distance math be done assuming
58      *      the world is a perfect sphere.  This is less compuntationally
59      *      expensive than using wgs84 math and still a fairly good
60      *      approximation of the real world, especially over shorter distances.
61      */
62     enum modetype { 
63         WGS84 = 0,
64         SPHERICAL = 1,
65     };
66
67 private:
68
69     modetype mode;
70
71     SGGeod pos;
72     double distance;
73
74     std::string id;
75     std::string name;
76
77 public:
78
79     /**
80      * Construct a waypoint
81      * @param lon destination longitude
82      * @param lat destination latitude
83      * @param alt target altitude
84      * @param mode type of coordinates/math to use
85      * @param s waypoint identifier
86      * @param n waypoint name
87      */
88     SGWayPoint( const double lon = 0.0, const double lat = 0.0,
89                 const double alt = 0.0, const modetype m = WGS84,
90                 const std::string& s = "", const std::string& n = "" );
91   
92     /**
93      * Construct from a geodetic position, in WGS84 coordinates
94      */
95     SGWayPoint(const SGGeod& pos, const std::string& s, const std::string& n);
96
97     /** Destructor */
98     ~SGWayPoint();
99
100     /**
101      * Calculate course and distances.  For WGS84 and SPHERICAL
102      * coordinates lat, lon, and course are in degrees, alt and
103      * distance are in meters.  For CARTESIAN coordinates x = lon, y =
104      * lat.  Course is in degrees and distance is in what ever units x
105      * and y are in.
106      * @param cur_lon (in) current longitude
107      * @param cur_lat (in) current latitude
108      * @param cur_alt (in) current altitude
109      * @param course (out) heading from current location to this waypoint
110      * @param dist (out) distance from current location to this waypoint
111      */
112     void CourseAndDistance( const double cur_lon, const double cur_lat,
113                             const double cur_alt,
114                             double *course, double *dist ) const;
115
116     void CourseAndDistance(const SGGeod& current,
117                             double& course, double& dist ) const;
118
119     /**
120      * Calculate course and distances between a specified starting waypoint
121      * and this waypoint.
122      * @param wp (in) original waypoint
123      * @param course (out) heading from current location to this waypoint
124      * @param dist (out) distance from current location to this waypoint
125      */
126     void CourseAndDistance( const SGWayPoint &wp,
127                             double *course, double *dist ) const;
128
129     /** @return waypoint longitude */
130     inline double get_target_lon() const { return pos.getLongitudeDeg(); }
131
132     /** @return waypoint latitude */
133     inline double get_target_lat() const { return pos.getLatitudeDeg(); }
134
135     /** @return waypoint altitude */
136     inline double get_target_alt() const { return pos.getElevationM(); }
137
138     inline const SGGeod& get_target() const { return pos; }
139
140     /**
141      * This value is not calculated by this class.  It is simply a
142      * placeholder for the user to stash a distance value.  This is useful
143      * when you stack waypoints together into a route.  You can calculate the
144      * distance from the previous waypoint once and save it here.  Adding up
145      * all the distances here plus the distance to the first waypoint gives you
146      * the total route length.  Note, you must update this value yourself, this
147      * is for your convenience only.
148      * @return waypoint distance holder (what ever the user has stashed here)
149      */
150     inline double get_distance() const { return distance; }
151
152     /**
153      * Set the waypoint distance value to a value of our choice.
154      * @param d distance 
155      */
156     inline void set_distance( double d ) { distance = d; }
157
158     /** @return waypoint id */
159     inline const std::string& get_id() const { return id; }
160
161     /** @return waypoint name */
162     inline const std::string& get_name() const { return name; }
163
164 };
165
166
167 #endif // _WAYPOINT_HXX