From 390c91316a1c4a07070f62f6f6e7fe86317b4537 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Wed, 11 Jun 2008 11:22:45 +0300 Subject: [PATCH] Path: Add a function to add a raw point, more documentation --- src/cb.c | 4 ++-- src/path.c | 39 +++++++++++++++++++++++++++++++-------- src/path.h | 8 ++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/cb.c b/src/cb.c index 0df98c5..204686c 100644 --- 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; } diff --git a/src/path.c b/src/path.c index af3c92c..2a8c3e7 100644 --- a/src/path.c +++ b/src/path.c @@ -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; + } /** diff --git a/src/path.h b/src/path.h index b13ee1e..2f9ecd1 100644 --- a/src/path.h +++ b/src/path.h @@ -25,6 +25,8 @@ #include #include +#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); -- 2.39.5