]> git.mxchange.org Git - simgear.git/blobdiff - simgear/route/route.hxx
Add project.* to MSVC project files
[simgear.git] / simgear / route / route.hxx
index cffeffd768684d8ddc7f50aed9ed6c6c774689a7..6c5c5c876d8901cb334738a8e007c94e18b0dfcc 100644 (file)
@@ -19,7 +19,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #define _ROUTE_HXX
 
 
-#ifndef __cplusplus                                                          
+#ifndef __cplusplus
 # error This library requires C++
-#endif                                   
-
+#endif
 
 #include <simgear/compiler.h>
 
-#include STL_STRING
 #include <vector>
 
-SG_USING_STD(string);
-SG_USING_STD(vector);
+using std::vector;
 
 #include <simgear/route/waypoint.hxx>
 
@@ -55,6 +52,8 @@ private:
     route_list route;
     int current_wp;
 
+    void update_distance_and_track(int index);
+
 public:
 
     /** Constructor */
@@ -70,21 +69,10 @@ 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 );
-
-       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
@@ -114,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
@@ -125,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 ) {
@@ -146,19 +154,15 @@ public:
     }
 
     /** Delete the front waypoint */
-    inline void delete_first() {
-       if ( route.size() ) {
-           route.erase( route.begin() );
-       }
-    }
+    inline void delete_first() { delete_waypoint(0); }
 
+    /** Delete waypoint waypoint with index n  (last one if n < 0) */
+    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;
 };