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++
35 #include <simgear/compiler.h>
41 #include <simgear/route/waypoint.hxx>
44 * A class to manage a list of waypoints (i.e. a route).
51 typedef vector < SGWayPoint > route_list;
55 void update_distance(int index);
65 /** Clear the entire route */
72 * Add waypoint (default), or insert waypoint at position n.
73 * @param wp a waypoint
75 void add_waypoint( const SGWayPoint &wp, int n = -1 );
77 * Get the number of waypoints (i.e. route length )
78 * @return route length
80 inline int size() const { return route.size(); }
83 * Get the front waypoint.
84 * @return the first waypoint.
86 inline SGWayPoint get_first() const {
90 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
95 * Get the current waypoint
96 * @return the current waypoint
98 inline SGWayPoint get_current() const {
99 if ( current_wp < (int)route.size() ) {
100 return route[current_wp];
102 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
107 * Set the current waypoint
108 * @param number of waypoint to make current.
110 inline void set_current( int n ) {
111 if ( n >= 0 && n < (int)route.size() ) {
116 inline int current_index() const {
120 /** Increment the current waypoint pointer. */
121 inline void increment_current() {
122 if ( current_wp < (int)route.size() - 1 ) {
128 * Get the nth waypoint
129 * @param n waypoint number
130 * @return the nth waypoint
132 inline SGWayPoint get_waypoint( const int n ) const {
133 if ( n < (int)route.size() ) {
136 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
140 /** Delete the front waypoint */
141 inline void delete_first() { delete_waypoint(0); }
143 /** Delete waypoint waypoint with index n (last one if n < 0) */
144 void delete_waypoint( int n = 0 );
147 * Calculate perpendicular distance from the current route segment
148 * This routine assumes all points are laying on a flat plane and
149 * ignores the altitude (or Z) dimension. For most accurate
150 * results, use with CARTESIAN way points.
152 double distance_off_route( double x, double y ) const;