From b0af84a5493962c565f0244985d0ffd93bcd55aa Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 8 May 2006 11:31:16 +0000 Subject: [PATCH] add optional position argument to SGRoute::add_waypoint(). Default is -1, which appends the WP like it used to. Valid vector indices insert the WP at this position. --- simgear/route/route.hxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/simgear/route/route.hxx b/simgear/route/route.hxx index 1eb57375..5d93992d 100644 --- a/simgear/route/route.hxx +++ b/simgear/route/route.hxx @@ -70,11 +70,14 @@ public: } /** - * Add a waypoint. + * Add waypoint (default), or insert waypoint at position n. * @param wp a waypoint */ - inline void add_waypoint( const SGWayPoint &wp ) { - route.push_back( wp ); + 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 ) { @@ -152,7 +155,7 @@ public: void delete_waypoint( int n = 0 ) { if ( !route.size() ) return; - if ( n < 0 || n > (int)route.size() - 1 ) + if ( n < 0 || n >= (int)route.size() ) n = route.size() - 1; route.erase( route.begin() + n ); -- 2.39.5