]> err.no Git - mapper/commitdiff
Path: Add a function to add a raw point, more documentation
authorKaj-Michael Lang <milang@tal.org>
Wed, 11 Jun 2008 08:22:45 +0000 (11:22 +0300)
committerKaj-Michael Lang <milang@tal.org>
Wed, 11 Jun 2008 08:22:45 +0000 (11:22 +0300)
src/cb.c
src/path.c
src/path.h

index 0df98c5fa047adf0b22ee502f652862798d51ca3..204686cff1acb99497087310de8f3ccf8ffe4eeb 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -908,7 +908,7 @@ cmenu_cb_loc_add_route(GtkAction *action)
 gdouble lat, lon;
 
 gtk_map_get_menu_latlon(_map, &lat, &lon);
-path_add_latlon(_route, lat, lon);
+path_add_latlon(_route, lat, lon, time(NULL), 0, 0);
 return TRUE;
 }
 
@@ -1242,7 +1242,7 @@ gdouble lat, lon;
 
 gtk_map_get_menu_latlon(_map, &lat, &lon);
 if (poi_select(lat, lon, 4, &poi))
-       path_add_latlon(_route, lat, lon);
+       path_add_latlon(_route, lat, lon, time(NULL), 0, 0);
 
 return TRUE;
 }
index af3c92c89fa883349dde6e0df85c7314ea1efcb0..2a8c3e770e265aacfbd42dfc3d7bca3f3ce51713 100644 (file)
@@ -245,7 +245,7 @@ return TRUE;
  * @path
  * @gps
  *
- * Append a path point to path
+ * Append a point using given gps data. Adds a path break if gps is not valid.
  *
  * Returns: TRUE if the new point was added. FALSE is returned if new point distance was under sensitivity setting.
  */
@@ -261,22 +261,44 @@ if (!gps) {
        return FALSE;
 }
 
-latlon2unit(gps->lat, gps->lon, unitx, unity);
+return path_add_latlon(path, gps->lat, gps->lon, gps->time, gps->speed, gps->altitude);
+}
+
+/**
+ * path_add_latlon:
+ * @path
+ * @lat
+ * @lon
+ * @ptime
+ * @speed
+ * @altitude
+ *
+ * Append a point with given lat,lon,ptime,speed and altitude to given path.
+ *
+ * Returns: TRUE if the new point was added. FALSE is returned if new point distance was under sensitivity setting.
+ */
+gboolean 
+path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude)
+{
+guint unitx, unity;
+
+latlon2unit(lat, lon, unitx, unity);
 
 if (abs((gint)unitx-path->tail->unitx) > path->sensitivity || abs((gint)unity-path->tail->unity) > path->sensitivity) {
        if (path->tail->unity && path->tail->unitx) {
-               gdouble lat, lon;
+               gdouble plat, plon;
 
                unit2latlon(path->tail->unitx, path->tail->unity, lat, lon);
-               path->length+=calculate_distance(lat, lon, gps->lat, gps->lon);
+               path->length+=calculate_distance(plat, plon, lat, lon);
        }
        MACRO_PATH_INCREMENT_TAIL(*path);
        path->tail->unitx=unitx;
        path->tail->unity=unity;
-       path->tail->time=gps->time;
-       path->tail->altitude=gps->altitude;
-       path->maxspeed=gps->maxspeed;
-       path->tspeed+=gps->speed;
+       path->tail->time=ptime;
+       path->tail->altitude=altitude;
+       if (speed>path->maxspeed)
+               path->maxspeed=speed;
+       path->tspeed+=speed;
        path->avgspeed=(path->points>0) ? path->tspeed/path->points : 0.0;
        path->points++;
        g_debug("TRACK: %f %f (%d)", path->length, path->avgspeed, path->points);
@@ -286,6 +308,7 @@ if (abs((gint)unitx-path->tail->unitx) > path->sensitivity || abs((gint)unity-pa
 }
 
 return FALSE;
+
 }
 
 /**
index b13ee1eec1f11f6641e4c8244ddf31f23d99bb99..2f9ecd16d1b983c1c40ff4d073e577a9f57cfb72 100644 (file)
@@ -25,6 +25,8 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
+#include "gpsdata.h"
+
 G_BEGIN_DECLS
 
 #define PATH_TYPE                              (path_get_type ())
@@ -173,6 +175,12 @@ gdouble path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
 void path_find_nearest_point(Path *path);
 gboolean path_update_nears(Path *route, Point *point, gboolean quick);
 
+gboolean path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude);
+gboolean path_add_point(Path *path, GpsData *gps);
+
+gboolean path_has_points(Path *path);
+gboolean path_has_waypoints(Path *path);
+
 gboolean path_add_break(Path *path);
 void path_insert_mark_text(Path *path, gchar *text);
 void path_insert_mark_autonumber(Path *path);