]> git.street.me.uk Git - andy/viking.git/commitdiff
Refix Merging tracks by time.
authorRob Norris <rw_norris@hotmail.com>
Wed, 26 Mar 2014 19:59:44 +0000 (19:59 +0000)
committerRob Norris <rw_norris@hotmail.com>
Wed, 26 Mar 2014 21:08:50 +0000 (21:08 +0000)
Accidentally broke it when trying to implement internal track ids.
(SHA: fc92c97715697980e8fde44b9dc8c02e29b1f7a0)

Somehow it previously did something, but it clearly wasn't actually
using *both* track times in deciding what to merge - d'oh!

It would also crash if one of the tracks has no trackpoints.
I think this flaw was in the original version.
This is now fixed as well.

src/viktrwlayer.c

index 75d800b29aee2c89ecac2d06b042a17be9e644d6..1c952cd5b690d31c9ad4e641fc7ec10604aca381 100644 (file)
@@ -5654,16 +5654,22 @@ static void find_tracks_with_timestamp_type(gpointer key, gpointer value, gpoint
   *(user_data->result) = g_list_prepend(*(user_data->result), key);
 }
 
-/* called for each key in track hash table. if original track user_data[1] is close enough
- * to the passed one, add it to list in user_data[0] 
+/**
+ * find_nearby_tracks_by_time:
+ *
+ * Called for each track in track hash table.
+ *  If the original track (in user_data[1]) is close enough (threshold period in user_data[2])
+ *  to the current track, then the current track is added to the list in user_data[0]
  */
 static void find_nearby_tracks_by_time (gpointer key, gpointer value, gpointer user_data)
 {
-  time_t t1, t2;
-  VikTrackpoint *p1, *p2;
   VikTrack *trk = VIK_TRACK(value);
 
   GList **nearby_tracks = ((gpointer *)user_data)[0];
+  VikTrack *orig_trk = VIK_TRACK(((gpointer *)user_data)[1]);
+
+  if ( !orig_trk || !orig_trk->trackpoints )
+    return;
 
   /* outline: 
    * detect reasons for not merging, and return
@@ -5676,12 +5682,13 @@ static void find_nearby_tracks_by_time (gpointer key, gpointer value, gpointer u
     return;
   }
 
-  t1 = vik_track_get_tp_first(trk)->timestamp;
-  t2 = vik_track_get_tp_last(trk)->timestamp;
+  time_t t1 = vik_track_get_tp_first(orig_trk)->timestamp;
+  time_t t2 = vik_track_get_tp_last(orig_trk)->timestamp;
 
   if (trk->trackpoints) {
-    p1 = vik_track_get_tp_first(trk);
-    p2 = vik_track_get_tp_last(trk);
+
+    VikTrackpoint *p1 = vik_track_get_tp_first(trk);
+    VikTrackpoint *p2 = vik_track_get_tp_last(trk);
 
     if (!p1->has_timestamp || !p2->has_timestamp) {
       //g_print("no timestamp\n");
@@ -6083,7 +6090,7 @@ static void trw_layer_merge_by_timestamp ( menu_array_sublayer values )
     }
 
     params[0] = &nearby_tracks;
-    params[1] = (gpointer)trps;
+    params[1] = orig_trk;
     params[2] = GUINT_TO_POINTER (threshold_in_minutes*60); // In seconds
 
     /* get a list of adjacent-in-time tracks */