X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Froute%2Froute.hxx;h=6c5c5c876d8901cb334738a8e007c94e18b0dfcc;hb=7bdb530440d1dadc991f305edb1b70ec85f27451;hp=5d93992da3f07c27e2a70a20e86627bfa152553a;hpb=b0af84a5493962c565f0244985d0ffd93bcd55aa;p=simgear.git diff --git a/simgear/route/route.hxx b/simgear/route/route.hxx index 5d93992d..6c5c5c87 100644 --- a/simgear/route/route.hxx +++ b/simgear/route/route.hxx @@ -32,14 +32,11 @@ # error This library requires C++ #endif - #include -#include STL_STRING #include -SG_USING_STD(string); -SG_USING_STD(vector); +using std::vector; #include @@ -55,6 +52,8 @@ private: route_list route; int current_wp; + void update_distance_and_track(int index); + public: /** Constructor */ @@ -73,21 +72,7 @@ public: * Add waypoint (default), or insert waypoint at position n. * @param wp a waypoint */ - void add_waypoint( const SGWayPoint &wp, int n = -1 ) { - if ( n < 0 || n >= (int)route.size() ) - route.push_back( wp ); - else - route.insert( route.begin() + n, 1, wp ); - - int size = route.size(); - if ( size > 1 ) { - SGWayPoint next_to_last = route[ size - 2 ]; - double tmpd, tmpc; - wp.CourseAndDistance( next_to_last, &tmpc, &tmpd ); - route[size - 1].set_distance( tmpd ); - } - } - + void add_waypoint( const SGWayPoint &wp, int n = -1 ); /** * Get the number of waypoints (i.e. route length ) * @return route length @@ -117,6 +102,22 @@ public: return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" ); } } + + inline SGWayPoint get_previous() const { + if ( (current_wp > 0) && (current_wp < (int)route.size()) ) { + return route[current_wp - 1]; + } else { + return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" ); + } + } + + inline SGWayPoint get_next() const { + if ( (current_wp + 1) < (int)route.size() ) { + return route[current_wp+1]; + } else { + return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" ); + } + } /** * Set the current waypoint @@ -128,6 +129,10 @@ public: } } + inline int current_index() const { + return current_wp; + } + /** Increment the current waypoint pointer. */ inline void increment_current() { if ( current_wp < (int)route.size() - 1 ) { @@ -152,22 +157,12 @@ public: inline void delete_first() { delete_waypoint(0); } /** Delete waypoint waypoint with index n (last one if n < 0) */ - void delete_waypoint( int n = 0 ) { - if ( !route.size() ) - return; - if ( n < 0 || n >= (int)route.size() ) - n = route.size() - 1; - - route.erase( route.begin() + n ); - } - + void delete_waypoint( int n = 0 ); + /** - * Calculate perpendicular distance from the current route segment - * This routine assumes all points are laying on a flat plane and - * ignores the altitude (or Z) dimension. For most accurate - * results, use with CARTESIAN way points. + * Helper, sum the distance members of each waypoint */ - double distance_off_route( double x, double y ) const; + double total_distance() const; };