1 // route.hxx -- Class to manage a list of waypoints (route)
3 // Written by Curtis Olson, started October 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 # error This library requires C++
37 #include <simgear/compiler.h>
45 #include <simgear/route/waypoint.hxx>
52 typedef vector < SGWayPoint > route_list;
61 // clear the entire route
68 inline void add_waypoint( const SGWayPoint &wp ) {
69 route.push_back( wp );
71 int size = route.size();
73 SGWayPoint next_to_last = route[ size - 2 ];
75 wp.CourseAndDistance( next_to_last, &tmpc, &tmpd );
76 route[size - 1].set_distance( tmpd );
80 // get the number of waypoints
81 inline int size() const { return route.size(); }
83 // get the front waypoint
84 inline SGWayPoint get_first() const {
88 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
92 // get the current waypoint
93 inline SGWayPoint get_current() const {
94 if ( current_wp < (int)route.size() ) {
95 return route[current_wp];
97 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
101 // set the current waypoint
102 inline void set_current( int n ) {
103 if ( n >= 0 && n < (int)route.size() ) {
108 // increment the current waypoint
109 inline void increment_current() {
110 if ( current_wp < (int)route.size() - 1 ) {
115 // get the nth waypoint
116 inline SGWayPoint get_waypoint( const int n ) const {
117 if ( n < (int)route.size() ) {
120 return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
124 // delete the front waypoint
125 inline void delete_first() {
126 if ( route.size() ) {
127 route.erase( route.begin() );
131 // Calculate perpendicular distance from the current route segment
132 // This routine assumes all points are laying on a flat plane and
133 // ignores the altitude (or Z) dimension. For best results, use
134 // with CARTESIAN way points.
135 double distance_off_route( double x, double y ) const;