Esempio n. 1
0
File: Form1.cs Progetto: Haurum/P2
        // Laver nye instanser af Runners og RunnerData, og kalder passende funktioner der læser data ind.
        private void LoadRunners(string[] GPXFiles)
        {
            int    ColorCount = 0;
            Runner runner;

            MainLeg.Name = string.Format("0 - {0}", ControlPoints.Count - 1);
            ControlPointTime cpt = new ControlPointTime();
            bool             reached;

            foreach (string file in GPXFiles)
            {
                runner = new Runner();
                runner.ReadGPXData(new FileStream(file, FileMode.Open));
                runner.reachedAll = true;
                runner.RouteColor = Colors[ColorCount % 6];
                ColorCount++;
                reached = true;

                // Tester om Runner har nået posterne
                foreach (ControlPoint cp in ControlPoints)
                {
                    cpt = new ControlPointTime();
                    cpt.ControlPointChecker(cp, runner);
                    runner.Visited.Add(cpt);
                    if (cpt.Cord == null)
                    {
                        reached = false;
                    }
                }

                RunnerData runnerdata = new RunnerData();
                runnerdata.name = runner.RunnerName;
                if (reached)
                {
                    runnerdata.distance = Helper.CalcTotalLength(runner, runner.Visited[0].Second,
                                                                 runner.Visited[runner.Visited.Count - 1].Second);
                    runnerdata.time = TimeSpan.FromSeconds(runner.Visited[runner.Visited.Count - 1].Second -
                                                           runner.Visited[0].Second);
                    runnerdata.speed = Helper.CalcSpeedMinsPrKm(runnerdata.distance, (int)(runnerdata.time.TotalSeconds));
                }
                else
                {
                    runnerdata.distance = 0;
                    runnerdata.time     = new TimeSpan(0);
                    runnerdata.speed    = 0;
                }

                runnerdata.reached = reached;
                MainLeg.Runners.Add(runnerdata);
                Runners.Add(runner);
            }
            MainLeg.Runners = Helper.GetPosAndDiff(MainLeg.Runners);
        }
Esempio n. 2
0
        // Tester om en runner har ramt det pågældende ControlPoint
        public void ControlPointChecker(ControlPoint cp, Runner r)
        {
            List <ControlPointTime> distList = new List <ControlPointTime>();
            ControlPointTime        cpt      = new ControlPointTime();
            double doubleDist = 0;

            foreach (Coordinate coord in r.Coords)
            {
                doubleDist = Helper.CalcSingleLength(coord.pixelPoint.X, coord.pixelPoint.Y, cp.Cord.pixelPoint.X, cp.Cord.pixelPoint.Y);
                if (doubleDist < 25)
                {
                    for (int i = r.Coords.IndexOf(coord); i < r.Coords.Count; i++)
                    {
                        if (Helper.CalcSingleLength(r.Coords[i].pixelPoint.X, r.Coords[i].pixelPoint.Y, cp.Cord.pixelPoint.X, cp.Cord.pixelPoint.Y) > 25)
                        {
                            ControlPointTime thisCpt = distList.OrderBy(distance => distance.Dist).First();
                            this.Cord   = thisCpt.Cord;
                            this.Dist   = thisCpt.Dist;
                            this.Number = thisCpt.Number;
                            this.Second = thisCpt.Second;
                            return;
                        }
                        cpt        = new ControlPointTime();
                        cpt.Cord   = cp.Cord;
                        cpt.Number = cp.Number;
                        cpt.Second = r.Coords.IndexOf(coord);
                        cpt.Dist   = Helper.CalcSingleLength(r.Coords[i].pixelPoint.X, r.Coords[i].pixelPoint.Y, cp.Cord.pixelPoint.X, cp.Cord.pixelPoint.Y);
                        cpt.Second = i;
                        distList.Add(cpt);
                    }
                }
            }
            this.Cord   = null;
            this.Dist   = 0;
            this.Number = 0;
            this.Second = 0;
            return;
        }