]> err.no Git - mapper/commitdiff
Path: Add missing functions to path.h + cleanups and fixes.
authorKaj-Michael Lang <milang@tal.org>
Wed, 23 Jul 2008 09:35:53 +0000 (12:35 +0300)
committerKaj-Michael Lang <milang@tal.org>
Wed, 23 Jul 2008 09:35:53 +0000 (12:35 +0300)
libs/libgtkmap/path.c
libs/libgtkmap/path.h

index ebb2d31e14040b035c9116d4677518fcac5fb6f8..9d69c4473978299c32f794ebe6910376a8149f7e 100644 (file)
@@ -39,6 +39,7 @@
 #include "path.h"
 #include "position.h"
 #include "latlon.h"
+#include "gtkmap.h"
 
 struct sql_select_stmt {
        sqlite3_stmt *select_paths;
@@ -589,6 +590,13 @@ path_update_nears(path, &p, FALSE);
 
 /**
  * path_find_nearest_waypoint:
+ * @path
+ * @lat
+ * @lon
+ *
+ * Try to find a waypoint near (from sensitivity setting) given lat,lon
+ *
+ * Returns: A WayPoint if found, NULL if not.
  *
  */
 WayPoint *
@@ -658,8 +666,13 @@ if (path->next_way_dist_squared<(a_thres_near * a_thres_near) && path->next_way!
 /******************************************************************************/
 
 /**
+ * path_calculate_distance_from:
+ * @path
+ * @point
  *
+ * Calculate the distance from path end back to the given point. Point MUST be on the path.
  *
+ * Returns: The calculated distance, negative value on errors.
  */
 gdouble
 path_calculate_distance_from(Path *path, Point *point)
@@ -668,8 +681,17 @@ Point *curr;
 gdouble lat1, lon1, lat2, lon2;
 gdouble sum=0.0;
 
-for (curr = path->tail; curr > point; --curr) {
-       if (curr->unity) {
+g_return_val_if_fail(path, -1.0);
+g_return_val_if_fail(point, -1.0);
+
+curr=path->tail;
+g_return_val_if_fail(path->tail, -1.0);
+g_return_val_if_fail(point>path->tail, -1.0);
+
+unit2latlon(curr->unitx, curr->unity, &lat1, &lon1);
+
+for (curr=path->tail;curr>point;--curr) {
+       if (curr && curr->unity && curr->unitx) {
                unit2latlon(curr->unitx, curr->unity, &lat2, &lon2);
                sum += calculate_distance(lat1, lon1, lat2, lon2);
                lat1 = lat2;
@@ -688,7 +710,7 @@ return sum;
  *
  * Calculate distancance from lat,lon to point in given path.
  *
- * Returns: The distance, or 0.0 if path or point is invalid.
+ * Returns: The distance, or negative value if path or point is invalid.
  */
 gdouble
 path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
@@ -696,7 +718,7 @@ path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
 gdouble lat1, lon1, lat2, lon2;
 gdouble sum=0.0;
 
-g_return_val_if_fail(path, 0.0);
+g_return_val_if_fail(path, -1.0);
 
 /* If point is NULL, use the next waypoint. */
 if (point == NULL && path->next_way)
@@ -741,6 +763,10 @@ return sum;
 
 /******************************************************************************/
 
+/**
+ * path_load:
+ *
+ */
 gboolean
 path_load(Path *path, const gchar *file)
 {
@@ -757,21 +783,26 @@ g_free(pfile);
 return TRUE;
 }
 
+/**
+ * path_save:
+ *
+ */
 gboolean 
 path_save(Path *path, const gchar *file)
 {
 GnomeVFSHandle *handle;
 gchar *tfile;
+gboolean res=FALSE;
 
 g_return_val_if_fail(path, FALSE);
 g_return_val_if_fail(file, FALSE);
 
 if (gnome_vfs_create(&handle, file, GNOME_VFS_OPEN_WRITE, FALSE, 0600)==GNOME_VFS_OK) {
-       path_gpx_write(path, handle, NULL);
+       res=path_gpx_write(path, handle, NULL);
        gnome_vfs_close(handle);
 }
 g_free(tfile);
-return TRUE;
+return res;
 }
 
 /******************************************************************************/
@@ -786,7 +817,7 @@ g_return_val_if_fail(path, FALSE);
 g_return_val_if_fail(pos, FALSE);
 
 if (path->head==path->tail) {
-       position_set(pos, FALSE, NAN, NAN, NAN);
+       position_clear(pos);
        return FALSE;
 }
 
@@ -795,7 +826,7 @@ if (p) {
        unit2latlon(p->unitx, p->unity, &lat, &lon);
        position_set(pos, TRUE, lat, lon, 0);
 } else {
-       position_set(pos, FALSE, NAN, NAN, NAN);
+       position_clear(pos);
        return FALSE;
 }
 return TRUE;
index 166a6eecc16af709bc292950ec6e1a8bb520a917..668bf7525991e6043bd296aa865f614246304e28 100644 (file)
@@ -180,10 +180,13 @@ gboolean path_gpx_parse(Path *to_replace, gchar *buffer, gint size, gpx_path_pol
 
 Point *path_find_last_point(Path *path);
 
+gdouble path_calculate_distance_from(Path *path, Point *point);
 gdouble path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon);
 
 void path_find_nearest_point(Path *path, gdouble lat, gdouble lon);
 
+WayPoint *path_find_nearest_waypoint(Path *path, gdouble lat, gdouble lon);
+
 gboolean path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude);
 gboolean path_add_waypoint(Path *path, gdouble lat, gdouble lon, gchar *desc);