Beispiel #1
0
        public static Image drawGroupFlights(Map map, Parcours parcours, CompetitorGroup group)
        {
            int competitorCounter = 0;

            Image img = drawParcours(map, parcours);
            Bitmap pg = new Bitmap(img.Width, img.Height);
            Graphics gr = Graphics.FromImage(pg);

            // clear the canvas to white
            Rectangle pgRect = new Rectangle(0, 0, pg.Width, pg.Height);
            SolidBrush solidWhite = new SolidBrush(Color.White);
            gr.FillRectangle(solidWhite, pgRect);
            // load a new image and draw it centered on our canvas

            Rectangle rc = new Rectangle(0, 0, img.Width, img.Height);
            gr.DrawImage(img, rc);
            img.Dispose();
            foreach (Competitor competitor in group.Competitors)
            {
                //Flight flight = competitor.getFlight(group);
                // ToDo: get flight
                Flight flight = null;
                Pen[] pens = new Pen[]{new Pen(Brushes.Blue, 3.0f), new Pen(Brushes.Aquamarine, 3.0f), new Pen(Brushes.BlueViolet, 3.0f), new Pen(Brushes.DeepSkyBlue, 3.0f)};
                Pen penInZone = new Pen(Brushes.LawnGreen, 5.0f);
                SolidBrush sb = new SolidBrush(Color.FromArgb(50, 250, 00, 20));
                double imagePointsLongitudeDifference = map.BottomRightPoint.Longitude - map.TopLeftPoint.Longitude;
                double imagePointsLatitudeDifference = map.TopLeftPoint.Latitude - map.BottomRightPoint.Latitude;

                Point[] points = new Point[flight.Track.Count];

                int i = 0;
                bool lastPointWasOffTrack = false;
                bool passedFinishingGate = false;
                List<Point> penaltyPoints = new List<Point>();
                List<List<Point>> penaltyPointsList = new List<List<Point>>();
                foreach (TrackPoint trackPoint in flight.Track)
                {

                    double currentPointLongitudeDifference = trackPoint.Longitude - map.TopLeftPoint.Longitude;
                    double currentPointLatitudeDifference = map.TopLeftPoint.Latitude - trackPoint.Latitude;
                    double currentPointImageX = (currentPointLongitudeDifference / imagePointsLongitudeDifference) * pg.Width;
                    double currentPointImageY = (currentPointLatitudeDifference / imagePointsLatitudeDifference) * pg.Height;

                    int mapPointX = int.Parse(Math.Ceiling(currentPointImageX).ToString());
                    int mapPointY = int.Parse(Math.Ceiling(currentPointImageY).ToString());

                    GraphicsPath p = new GraphicsPath();
                    for (int j = 0; j < 4; j++)
                    {
                        if (Common.gatePassed(parcours.Gates[j, 1], trackPoint, flight.Track[i + 1]))
                        {
                            passedFinishingGate = true;
                        }
                    }
                    if (!passedFinishingGate && parcours.IsPointOffTrack(trackPoint))
                    {
                        lastPointWasOffTrack = true;
                        penaltyPoints.Add(new Point(mapPointX, mapPointY));
                    }
                    else
                    {
                        if (lastPointWasOffTrack)
                        {
                            penaltyPointsList.Add(penaltyPoints);
                            penaltyPoints = new List<Point>();
                        }
                        lastPointWasOffTrack = false;
                    }

                    points[i] = new Point(mapPointX, mapPointY);
                    if (i < flight.Track.Count - 2)
                    {
                        i++;
                    }
                }
                gr.DrawLines(pens[competitorCounter], points);

                foreach (List<Point> penaltyPts in penaltyPointsList)
                {
                    Point[] pointarray = penaltyPts.ToArray();
                    gr.DrawLines(penInZone, pointarray);
                }
                competitorCounter++;
            }
            return pg;
        }
Beispiel #2
0
        /// <summary>
        /// Returns the Penalties for a flight on a Parcours (Forbidden Zones only)
        /// </summary>
        /// <param name="parcours"></param>
        /// <param name="flight"></param>
        /// <returns></returns>
        public static PenaltyCollection calculateForbiddenZonePenalties(Parcours parcours, Flight flight)
        {
            bool lastPointWasOffTrack = false;
            bool finishingGatePassed = false;
            List<GpsPoint> penaltyPoints = new List<GpsPoint>();

            List<List<GpsPoint>> penaltyPointsList = new List<List<GpsPoint>>();

            for (int i = 0; i< flight.Track.Count-1; i++)
            {
                if(!finishingGatePassed)
                {
                    TrackPoint trackpoint = flight.Track[i];
                    for(int j = 0; j<4;j++)
                    {
                        // ToDo: get gate
                        //if(Common.gatePassed(parcours.Gates[j,1] ,trackpoint, flight.Track[i+1]))
                        //{
                        //    finishingGatePassed = true;
                        //    break;
                        //}
                        if (parcours.IsPointOffTrack(trackpoint))
                        {
                            lastPointWasOffTrack = true;
                            penaltyPoints.Add(trackpoint);
                        }
                        else
                        {
                            if (lastPointWasOffTrack)
                            {
                                penaltyPointsList.Add(penaltyPoints);
                                penaltyPoints = new List<GpsPoint>();
                            }
                            lastPointWasOffTrack = false;
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            PenaltyCollection penalties = new PenaltyCollection();
            foreach (List<GpsPoint> penaltySequence in penaltyPointsList)
            {
                int durance = penaltySequence.Count;
                Rules.RestrictedAreaDuration restrictedAreaDuration;

                if(durance <= 2)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.ZeroToTwo;
                else if(durance >=3 && durance <= 4)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.ThreeToFour;
                else if(durance >=5 && durance <= 6)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.FiveToSix;
                else if(durance >=7 && durance <= 8)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.SevenToEight;
                else if(durance >=9 && durance <=10)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.NineToTen;
                else
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.MoreOrEqEleven;

                Penalty newPenalty = new Penalty();
                // ToDo: assign penalty point, comment, etc.
                penalties.Add(newPenalty);
            }
            return penalties;
        }