gdouble len = 0.0;
if ( tr->trackpoints )
{
+ // Is it the very first track point?
+ if ( VIK_TRACKPOINT(tr->trackpoints->data) == tp )
+ return len;
+
GList *iter = tr->trackpoints->next;
while (iter)
{
// Exit when we reach the desired point
if ( tp1 == tp )
- break;
+ break;
iter = iter->next;
}
}
}
+/**
+ * vik_track_get_duration:
+ * @trk: The track
+ *
+ * Returns: The time in seconds that covers the whole track including gaps
+ * NB this may be negative particularly if the track has been reversed
+ */
+time_t vik_track_get_duration(const VikTrack *trk)
+{
+ time_t duration = 0;
+ if ( trk->trackpoints ) {
+ // Ensure times are available
+ if ( vik_track_get_tp_first(trk)->has_timestamp ) {
+ // Get trkpt only once - as using vik_track_get_tp_last() iterates whole track each time
+ VikTrackpoint *trkpt_last = vik_track_get_tp_last(trk);
+ if ( trkpt_last->has_timestamp ) {
+ time_t t1 = vik_track_get_tp_first(trk)->timestamp;
+ time_t t2 = trkpt_last->timestamp;
+ duration = t2 - t1;
+ }
+ }
+ }
+ return duration;
+}
+
gdouble vik_track_get_average_speed(const VikTrack *tr)
{
gdouble len = 0.0;
while ( iter->prev ) {
- if ( vik_coord_equals((VikCoord *)iter->data, (VikCoord *)iter->prev->data) ) {
+ VikCoord *cur_coord = &((VikTrackpoint*)iter->data)->coord;
+ VikCoord *prev_coord = &((VikTrackpoint*)iter->prev->data)->coord;
+ if ( vik_coord_equals(cur_coord, prev_coord) ) {
GList *prev = iter->prev;
rv = g_malloc(sizeof(VikCoord));
- *rv = *((VikCoord *) iter->data);
+ *rv = *cur_coord;
/* truncate trackpoint list */
iter->prev = NULL; /* pretend it's the end */
/* no double point found! */
rv = g_malloc(sizeof(VikCoord));
- *rv = *((VikCoord *) tr->trackpoints->data);
+ *rv = ((VikTrackpoint*) tr->trackpoints->data)->coord;
g_list_foreach ( tr->trackpoints, (GFunc) g_free, NULL );
g_list_free( tr->trackpoints );
tr->trackpoints = NULL;