]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrack.c
[QA] Tidy up vikgoto header usage.
[andy/viking.git] / src / viktrack.c
index 91e060f193fe27ed16c5c0ff29094e45361dd527..f0c3c6c88f7947ce654521ab7f331e55f158368a 100644 (file)
@@ -122,20 +122,35 @@ void vik_track_free(VikTrack *tr)
   g_free ( tr );
 }
 
-VikTrack *vik_track_copy ( const VikTrack *tr )
+/**
+ * vik_track_copy:
+ * @tr: The Track to copy
+ * @copy_points: Whether to copy the track points or not
+ *
+ * Normally for copying the track it's best to copy all the trackpoints
+ * However for some operations such as splitting tracks the trackpoints will be managed separately, so no need to copy them.
+ *
+ * Returns: the copied VikTrack
+ */
+VikTrack *vik_track_copy ( const VikTrack *tr, gboolean copy_points )
 {
   VikTrack *new_tr = vik_track_new();
   VikTrackpoint *new_tp;
   GList *tp_iter = tr->trackpoints;
   new_tr->visible = tr->visible;
   new_tr->is_route = tr->is_route;
+  new_tr->has_color = tr->has_color;
+  new_tr->color = tr->color;
   new_tr->trackpoints = NULL;
-  while ( tp_iter )
+  if ( copy_points )
   {
-    new_tp = g_malloc ( sizeof ( VikTrackpoint ) );
-    *new_tp = *((VikTrackpoint *)(tp_iter->data));
-    new_tr->trackpoints = g_list_append ( new_tr->trackpoints, new_tp );
-    tp_iter = tp_iter->next;
+    while ( tp_iter )
+    {
+      new_tp = g_malloc ( sizeof ( VikTrackpoint ) );
+      *new_tp = *((VikTrackpoint *)(tp_iter->data));
+      new_tr->trackpoints = g_list_append ( new_tr->trackpoints, new_tp );
+      tp_iter = tp_iter->next;
+    }
   }
   vik_track_set_name(new_tr,tr->name);
   vik_track_set_comment(new_tr,tr->comment);
@@ -357,7 +372,7 @@ VikTrack **vik_track_split_into_segments(VikTrack *t, guint *ret_len)
   }
 
   rv = g_malloc ( segs * sizeof(VikTrack *) );
-  tr = vik_track_copy ( t );
+  tr = vik_track_copy ( t, TRUE );
   rv[0] = tr;
   iter = tr->trackpoints;
 
@@ -368,16 +383,7 @@ VikTrack **vik_track_split_into_segments(VikTrack *t, guint *ret_len)
     {
       iter->prev->next = NULL;
       iter->prev = NULL;
-      rv[i] = vik_track_new();
-      // TODO: consider new naming strategy here
-      if ( tr->name )
-        vik_track_set_name ( rv[i], tr->name );
-      if ( tr->comment )
-        vik_track_set_comment ( rv[i], tr->comment );
-      if ( tr->description )
-        vik_track_set_description ( rv[i], tr->description );
-      rv[i]->visible = tr->visible;
-      rv[i]->is_route = tr->is_route;
+      rv[i] = vik_track_copy ( tr, FALSE );
       rv[i]->trackpoints = iter;
       i++;
     }
@@ -1266,6 +1272,8 @@ VikTrack *vik_track_unmarshall (guint8 *data, guint datalen)
   /* basic properties: */
   new_tr->visible = ((VikTrack *)data)->visible;
   new_tr->is_route = ((VikTrack *)data)->is_route;
+  new_tr->has_color = ((VikTrack *)data)->has_color;
+  new_tr->color = ((VikTrack *)data)->color;
 
   data += sizeof(*new_tr);
 
@@ -1312,7 +1320,9 @@ void vik_track_apply_dem_data ( VikTrack *tr )
   }
 }
 
-/*
+/**
+ * vik_track_apply_dem_data_last_trackpoint:
+ * 
  * Apply DEM data (if available) - to only the last trackpoint
  */
 void vik_track_apply_dem_data_last_trackpoint ( VikTrack *tr )
@@ -1326,7 +1336,11 @@ void vik_track_apply_dem_data_last_trackpoint ( VikTrack *tr )
   }
 }
 
-/* appends t2 to t1, leaving t2 with no trackpoints */
+/**
+ * vik_track_steal_and_append_trackpoints:
+ * 
+ * appends t2 to t1, leaving t2 with no trackpoints
+ */
 void vik_track_steal_and_append_trackpoints ( VikTrack *t1, VikTrack *t2 )
 {
   if ( t1->trackpoints ) {
@@ -1340,9 +1354,13 @@ void vik_track_steal_and_append_trackpoints ( VikTrack *t1, VikTrack *t2 )
   t2->trackpoints = NULL;
 }
 
-/* starting at the end, looks backwards for the last "double point", a duplicate trackpoint.
+/**
+ * vik_track_cut_back_to_double_point:
+ * 
+ * starting at the end, looks backwards for the last "double point", a duplicate trackpoint.
  * If there is no double point, deletes all the trackpoints.
- * Returns the new end of the track (or the start if there are no double points)
+ * 
+ * Returns: the new end of the track (or the start if there are no double points)
  */
 VikCoord *vik_track_cut_back_to_double_point ( VikTrack *tr )
 {