private TimeSpan ComputeDuration(List <GPSLogEntry> entries)
        {
            int start = -1;
            int end   = -1;

            for (int i = 0; i < entries.Count - 1; i++)
            {
                if (Constants.MIN_SPEED <= GlobalPoint.Distance(entries[i + 1], entries[i]) / ((double)(entries[i + 1].Time.Ticks - entries[i].Time.Ticks) / TimeSpan.TicksPerSecond))
                {
                    start = i;
                    break;
                }
            }
            for (int i = entries.Count - 1; i > 0; i--)
            {
                if (Constants.MIN_SPEED <= GlobalPoint.Distance(entries[i - 1], entries[i]) / ((double)(entries[i].Time.Ticks - entries[i - 1].Time.Ticks) / TimeSpan.TicksPerSecond))
                {
                    end = i;
                    break;
                }
            }
            if (start < end && start != -1)
            {
                new TimeSpan(entries[end].Time.Ticks - entries[start].Time.Ticks);
            }
            return(new TimeSpan(entries[entries.Count - 1].Time.Ticks - entries[0].Time.Ticks));
        }
        private static List <GPSLogEntry> GetApproximatingNodes(List <GPSLogEntry> fullSet, int targetCount = 7)
        {
            const double step = 0.0001;                             // the stemp by which bioas is incremented.
            const int    minModificationsPerRun = 20;               // allows to increase bias even if modifications were performed.
            int          strictBiasBound        = targetCount * 16; // defines the bound after which optimisations are removed

            List <GPSLogEntry> a, b;

            a = fullSet;
            b = new List <GPSLogEntry>(fullSet.Count);
            int    modified = 0;
            double bias     = 0;
            double sum      = 0;
            double avg      = 1;

            while (a.Count > targetCount)
            {
                //Console.WriteLine(a.Count + "  bias: " + bias + " avg: " + avg);
                b.Add(a[0]);
                for (int i = 1; i < a.Count - 1; i++)
                {
                    double A = GlobalPoint.Distance(a[i - 1], a[i]);                    // distancec too previus node
                    double B = GlobalPoint.Distance(a[i + 1], a[i]);                    // distance to the next node
                    double C = GlobalPoint.Distance(a[i - 1], a[i + 1]);                // distance between neighbouring nodes
                    //removes nodes with the least impact on total length (favours removal of nodes with nodes closer than average)
                    if (A + B <= C * (1 + bias * (avg / C)))
                    {
                        modified++;
                        i++;
                        b.Add(a[i]);
                        sum += C;
                    }
                    else
                    {
                        b.Add(a[i]);
                        sum += A;
                    }
                }
                if (!b[b.Count - 1].Equals(a[a.Count - 1]))
                {
                    b.Add(a[a.Count - 1]);
                }

                if (modified < minModificationsPerRun && (b.Count > strictBiasBound || modified <= 1))
                {
                    bias += step;
                }
                else
                {
                    modified = 0;
                }
                //formula works better if avg value is less than true average; Mhen list is small, correction for length is too great, thus avg value is locked at final stages
                avg = (a.Count >= strictBiasBound) ? (avg + avg + (sum / b.Count)) / 3 : avg;
                a   = b;
                b   = new List <GPSLogEntry>(a.Count);
            }
            return(a);
        }
        private double ComputeLength(List <GPSLogEntry> entries, bool approximate = false)
        {
            GPSLogEntry prev = null;
            double      ret  = 0;

            foreach (var entry in entries)
            {
                if (!approximate || entry.ApproximatingFix)
                {
                    if (prev != null)
                    {
                        ret += GlobalPoint.Distance(prev, entry);
                    }
                    prev = entry;
                }
            }
            return(ret);
        }
Exemple #4
0
        internal async Task <bool> IsGlobalPointValidForNewAirfield(Airfield airfield)
        {
            var temp = await _airfieldRepository.FilterListShallowAsync(ent => GlobalPoint.Distance(ent, airfield) < 2 *Constants.AIRFIELD_DESIGNATED_AREA_RADIUS);

            return(temp.Count == 0);
        }
 public Task <Airfield> FindAround(IGlobalPoint globalPoint)
 {
     return(GetFullIncludes()
            .SingleAsync(ent => GlobalPoint.Distance(ent, globalPoint) <= Constants.AIRFIELD_DESIGNATED_AREA_RADIUS));
 }