public static void InsertValue <T>(DateTime atime, ITimeDataSeries <T> track, ITimeDataSeries <T> source) { //Interpolation is down to seconds //TBD: Inefficient, source.IndexOf often fails #if ST_3_1_5314_BUG //http://www.zonefivesoftware.com/sporttracks/forums/viewtopic.php?p=84638#p84638 //System.Exception: FindPosOnOrBefore: Didn't find element properly. try { #endif ITimeValueEntry <T> interpolatedP = source.GetInterpolatedValue(atime); if (interpolatedP != null) { int index = source.IndexOf(interpolatedP); T val = interpolatedP.Value; if (index >= 0) { val = TrackUtil.getValFromDateTimeIndex(source, atime, index); } else { } try { #if !NO_ST_INSERT_START_TIME //ST bug: not inserted in order if ms differs for start if (Math.Abs((atime - track.StartTime).TotalSeconds) < 1) { track.RemoveAt(0); } #endif track.Add(atime, val); //T val2 = track.GetInterpolatedValue(atime).Value; } catch { } } #if ST_3_1_5314_BUG } catch (Exception e) { } #endif }
/****************************************************/ //Before ST 3_0_4205 points was not always inserted in order //For some reason this occasionally occurs in Trails 1.2.821 too public static bool ResortTrack <T>(ITimeDataSeries <T> track) { bool reSort = false; #if !NO_ST_RESORT_TRACKS if (track.Count > 0) { for (int i = 1; i < track.Count; i++) { if (track[i - 1].ElapsedSeconds > track[i].ElapsedSeconds) { reSort = true; break; } } if (reSort) { SortedDictionary <uint, ITimeValueEntry <T> > dic = new SortedDictionary <uint, ITimeValueEntry <T> >(); foreach (ITimeValueEntry <T> g in track) { if (!dic.ContainsKey(g.ElapsedSeconds)) { dic.Add(g.ElapsedSeconds, g); } } DateTime startTimeTrack = track.StartTime; track.Clear(); foreach (KeyValuePair <uint, ITimeValueEntry <T> > g in dic) { track.Add(startTimeTrack.AddSeconds(g.Value.ElapsedSeconds), g.Value.Value); } } } #endif return(reSort); }