]> err.no Git - mapper/commitdiff
Update path data fields with length, avg speed and points when adding points.
authorKaj-Michael Lang <milang@onion.tal.org>
Fri, 7 Mar 2008 13:07:25 +0000 (15:07 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Fri, 7 Mar 2008 13:07:25 +0000 (15:07 +0200)
src/track.c

index 363fcd1b04dbff7419ae5d2bf6d9d74a1488b153..791a928cb249367b89b76560debf8ce82af4fd57 100644 (file)
@@ -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) {