3 * Provides a class to manage a list of waypoints (i.e. a route).
6 // Written by Curtis Olson, started October 2000.
8 // Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
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.
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.
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.
32 # error This library requires C++
36 #include <simgear/compiler.h>
44 #include <simgear/route/waypoint.hxx>
47 * A class to manage a list of waypoints (i.e. a route).
54 typedef vector < SGWayPoint > route_list;
66 /** Clear the entire route */
74 * @param wp a waypoint
76 inline void add_waypoint( const SGWayPoint &wp ) {
77 route.push_back( wp );
79 int size = route.size();
81 SGWayPoint next_to_last = route[ size - 2 ];
83 wp.CourseAndDistance( next_to_last, &tmpc, &tmpd );
84 route[size - 1].set_distance( tmpd );
89 * Get the number of waypoints (i.e. route length )
90 * @return route length
92 inline int size() const { return route.size(); }
95 * Get the front waypoint.
96 * @return the first waypoint.
98 inline SGWayPoint get_first() const {
102 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
107 * Get the current waypoint
108 * @return the current waypoint
110 inline SGWayPoint get_current() const {
111 if ( current_wp < (int)route.size() ) {
112 return route[current_wp];
114 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
119 * Set the current waypoint
120 * @param number of waypoint to make current.
122 inline void set_current( int n ) {
123 if ( n >= 0 && n < (int)route.size() ) {
128 /** Increment the current waypoint pointer. */
129 inline void increment_current() {
130 if ( current_wp < (int)route.size() - 1 ) {
136 * Get the nth waypoint
137 * @param n waypoint number
138 * @return the nth waypoint
140 inline SGWayPoint get_waypoint( const int n ) const {
141 if ( n < (int)route.size() ) {
144 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
148 /** Delete the front waypoint */
149 inline void delete_first() {
150 if ( route.size() ) {
151 route.erase( route.begin() );
156 * Calculate perpendicular distance from the current route segment
157 * This routine assumes all points are laying on a flat plane and
158 * ignores the altitude (or Z) dimension. For most accurate
159 * results, use with CARTESIAN way points.
161 double distance_off_route( double x, double y ) const;