From eeba31e9ad11c5549bfb72deeb01131a449ad508 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 7 Mar 2008 15:07:25 +0200 Subject: [PATCH] Update path data fields with length, avg speed and points when adding points. --- src/track.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/track.c b/src/track.c index 363fcd1..791a928 100644 --- a/src/track.c +++ b/src/track.c @@ -50,6 +50,8 @@ confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Clear the track?" if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { _track.tail = _track.head; + _track.length=_track.avgspeed=0.0; + _track.points=0; map_force_redraw(); } gtk_widget_destroy(confirm); @@ -158,6 +160,8 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->uni ty1 = unit2y(_track.tail->unity); tx2 = unit2x(gps->unitx); ty2 = unit2y(gps->unity); + + /* XXX: This should not be here... */ gtk_widget_queue_draw_area(_map_widget, MIN(tx1, tx2) - _draw_width, MIN(ty1, ty2) - _draw_width, @@ -166,11 +170,25 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->uni } } + if (_track.tail->unity && _track.tail->unitx) { + gdouble lat, lon; + + unit2latlon(_track.tail->unitx, _track.tail->unity, lat, lon); + _track.length += calculate_distance(lat, lon, gps->lat, gps->lon); + _track.tspeed+=gps->speed; + if (_track.points>0) + _track.avgspeed=_track.tspeed/_track.points; + else + _track.avgspeed=0.0; + g_debug("TRACK: %f %f (%d)", _track.length, _track.avgspeed, _track.points); + } + MACRO_PATH_INCREMENT_TAIL(_track); _track.tail->unitx=gps->unitx; _track.tail->unity=gps->unity; _track.tail->time=gps->time; _track.tail->altitude=gps->altitude; + _track.points++; } if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) { -- 2.39.5