Exemplo n.º 1
0
        protected int DrawPath(Bitmap image, Graphics graphics, Point start, Point end, out TimeSpan time)
        {
            // performs boundary check first
            BasePathScenario.CheckBounds(ref start, ref end, DefaultAreaWidth, DefaultAreaHeight);

            // determines the options
            bool flagPerformOptimizations = (bool)Invoke(getOption, checkPerformOptimization);
            bool flagDrawPivotPoints      = (bool)Invoke(getOption, checkDrawPivotPoints);
            bool flagDrawLargerPivots     = (bool)Invoke(getOption, checkDrawLargerPivots);

            // initializes the parameters
            int result = 0;
            IReadOnlyCollection <Point> points;
            IReadOnlyCollection <Point> pivotPoints;

            // finds the path while measuring time elapsed
            DateTime startDate          = DateTime.Now;
            float    precisionAlignment = objectDiameter % 2 == 0 ? 0.5f : 0.0f;
            Pen      pen = new Pen(Color.DarkGreen)
            {
                Width = objectDiameter - precisionAlignment, StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round
            };

            bool found = activePathFinder.TryFindPath(start, end, stopFunction, out points, out pivotPoints, flagPerformOptimizations);

            time = DateTime.Now - startDate;

            if (found)
            {
                // draws connected lines through all the points
                if (points.Count > 1)
                {
                    graphics.DrawLines(pen, points.ToArray());
                }

                // draws markers at pivot points (if turned on)
                if (flagDrawPivotPoints && pivotPoints != null)
                {
                    foreach (Point highlightPoint in pivotPoints)
                    {
                        if (flagDrawLargerPivots)
                        {
                            DrawMarker(graphics, highlightPoint, Brushes.Red, true);
                        }
                        else
                        {
                            image.SetPixel(highlightPoint.X, highlightPoint.Y, Color.Red);
                        }
                    }
                }

                result = points.Count;
            }

            return(result);
        }
Exemplo n.º 2
0
        private void ChangeScenario()
        {
            activeScenario = scenarioList[listScenarios.SelectedIndex];

            taskList.Add(() =>
            {
                RecreateDefaultImage(false, needsUpdate);
                needsUpdate = false;
            });
        }