]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrack.c
Remove now unused alphabetical sort functions as they have been superseded.
[andy/viking.git] / src / viktrack.c
index fefb8e6b4faf73991ca0d7f59a57fcc2ecb85e2f..5422e7843aa619a85335c2734e7ce2780577e97e 100644 (file)
@@ -180,6 +180,48 @@ VikTrackpoint *vik_trackpoint_copy(VikTrackpoint *tp)
   return rv;
 }
 
+/**
+ * track_recalculate_bounds_last_tp:
+ * @trk:   The track to consider the recalculation on
+ *
+ * A faster bounds check, since it only considers the last track point
+ */
+static void track_recalculate_bounds_last_tp ( VikTrack *trk )
+{
+  GList *tpl = g_list_last ( trk->trackpoints );
+
+  if ( tpl ) {
+    struct LatLon ll;
+    // See if this trackpoint increases the track bounds and update if so
+    vik_coord_to_latlon ( &(VIK_TRACKPOINT(tpl->data)->coord), &ll );
+    if ( ll.lat > trk->bbox.north )
+      trk->bbox.north = ll.lat;
+    if ( ll.lon < trk->bbox.west )
+      trk->bbox.west = ll.lon;
+    if ( ll.lat < trk->bbox.south )
+      trk->bbox.south = ll.lat;
+    if ( ll.lon > trk->bbox.east )
+      trk->bbox.east = ll.lon;
+  }
+}
+
+/**
+ * vik_track_add_trackpoint:
+ * @tr:          The track to which the trackpoint will be added
+ * @tp:          The trackpoint to add
+ * @recalculate: Whether to perform any associated properties recalculations
+ *               Generally one should avoid recalculation via this method if adding lots of points
+ *               (But ensure calculate_bounds() is called after adding all points!!)
+ *
+ * The trackpoint is added to the end of the existing trackpoint list
+ */
+void vik_track_add_trackpoint ( VikTrack *tr, VikTrackpoint *tp, gboolean recalculate )
+{
+  tr->trackpoints = g_list_append ( tr->trackpoints, tp );
+  if ( recalculate )
+    track_recalculate_bounds_last_tp ( tr );
+}
+
 gdouble vik_track_get_length(const VikTrack *tr)
 {
   gdouble len = 0.0;