#include "path.h"
#include "position.h"
#include "latlon.h"
+#include "gtkmap.h"
struct sql_select_stmt {
sqlite3_stmt *select_paths;
/**
* 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 *
/******************************************************************************/
/**
+ * 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)
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;
*
* 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)
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)
/******************************************************************************/
+/**
+ * path_load:
+ *
+ */
gboolean
path_load(Path *path, const gchar *file)
{
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;
}
/******************************************************************************/
g_return_val_if_fail(pos, FALSE);
if (path->head==path->tail) {
- position_set(pos, FALSE, NAN, NAN, NAN);
+ position_clear(pos);
return FALSE;
}
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;
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);