//Exclude the pauses from the selection
        public static IValueRangeSeries <DateTime> excludePauses(IValueRangeSeries <DateTime> sels, IValueRangeSeries <DateTime> pauses)
        {
            IValueRangeSeries <DateTime> t = new ValueRangeSeries <DateTime>();

            foreach (IValueRange <DateTime> tsel in sels)
            {
                foreach (IValueRange <DateTime> t1 in DateTimeRangeSeries.TimesNotPaused(
                             tsel.Lower, tsel.Upper, pauses))
                {
                    t.Add(t1);
                }
            }
            return(t);
        }
        public static IList <IList <IGPSPoint> > GpsPoints(IGPSRoute gpsRoute, IValueRangeSeries <DateTime> selections)
        {
            IList <IList <IGPSPoint> > result = new List <IList <IGPSPoint> >();

            if (selections != null && selections.Count > 0 && gpsRoute != null && gpsRoute.Count > 1)
            {
                //selection and gps points are sorted without overlap so traverse over gps points only once
                //(previous version had much more complicated version, that also accounted for pauses)
                int i = 0;
                foreach (IValueRange <DateTime> sel in selections)
                {
                    IList <IGPSPoint> track = new List <IGPSPoint>();
                    //Use start/end "with priority", even if extra points are added. Care needed if returning GPSRoute
                    DateTime t = DateTimeRangeSeries.Latest(sel.Lower, gpsRoute.StartTime);
                    ITimeValueEntry <IGPSPoint> pt = gpsRoute.GetInterpolatedValue(t);
                    if (pt != null)
                    {
                        track.Add(pt.Value);
                    }
                    while (i < gpsRoute.Count)
                    {
                        ITimeValueEntry <IGPSPoint> entry = gpsRoute[i];
                        DateTime time = gpsRoute.EntryDateTime(entry);
                        i++;
                        if (sel.Lower > time)
                        {
                            continue;
                        }
                        if (sel.Upper < time)
                        {
                            //Do not increase counter here, it could be needed
                            i--;
                            break;
                        }
                        track.Add(entry.Value);
                    }
                    t  = DateTimeRangeSeries.Earliest(sel.Upper, gpsRoute.StartTime.AddSeconds(gpsRoute.TotalElapsedSeconds));
                    pt = gpsRoute.GetInterpolatedValue(t);
                    if (pt != null)
                    {
                        track.Add(pt.Value);
                    }
                    result.Add(track);
                }
            }

            return(result);
        }
        //ST IsPaused reports no pause if time matches, this also checks borders
        private static bool IsPause(DateTime time, IValueRangeSeries <DateTime> pauses)
        {
            bool res = DateTimeRangeSeries.IsPaused(time, pauses);

            if (!res)
            {
                foreach (IValueRange <DateTime> pause in pauses)
                {
                    if (time.CompareTo(pause.Lower) >= 0 &&
                        time.CompareTo(pause.Upper) <= 0)
                    {
                        res = true;
                        break;
                    }
                }
            }
            return(res);
        }