Example #1
0
 public FloodFillDrawer(PolygonsContainer data, MethodInvoker ImageRefresher = null)
 {
     this.ImageRefresher = ImageRefresher;
     this.data = data;
     InitializeFloodFillStrategies();
     floodFillerStrategy = strategiesList[0];
 }
Example #2
0
 public void Init(Vector2[][] obstacles)
 {
     stopwatch = new Stopwatch();
     stopwatch.Start();
     map = MapBuilder.Build(obstacles);
     stopwatch.Stop();
     Console.WriteLine("total init time is " + stopwatch.Elapsed.TotalMilliseconds);
     pathFinder = new Finder(map);
 }
Example #3
0
        private void TraceContainer(PolygonsContainer container)
        {
            var currentContainer = container;
            var segment          = new Segment(currentPoint, goal);

            if (currentContainer.IsEmpty())
            {
                return;
            }

            if (!currentContainer.LayInSegmentBounds(segment))
            {
                return;
            }
            do
            {
                if (currentContainer.HasChildren)
                {
                    if (currentContainer.Contains(currentPoint))
                    {
                        var child = currentContainer.GetChildContainedPoint(currentPoint);
                        if (child != null && !excludedPolygons.Contains(child.GetId()))
                        {
                            currentContainer = child;
                            continue;
                        }
                    }
                    var intersection = FindNearestPolygonIntersection(currentContainer.ChildContainers);
                    if (intersection == null)
                    {
                        excludedPolygons.Add(currentContainer.GetId());
                        currentContainer = currentContainer.Parent;
                        if (currentContainer == null)
                        {
                            break;
                        }

                        continue;
                    }
                    currentContainer = intersection.Polygon as PolygonsContainer;
                }
                else if (currentContainer.HasPolygons())
                {
                    excludedPolygons.Add(currentContainer.GetId());
                    TracePolygons(currentContainer.Polygons);
                    if (currentContainer.HasParent)
                    {
                        currentContainer = currentContainer.Parent;
                    }
                    else
                    {
                        return;
                    }
                }
            } while (true);
        }
Example #4
0
        public MainForm()
        {
            InitializeComponent();

            var drawArea = AppUtils.InitializeDrawArea(CONSTS.areaMaxWidth, CONSTS.areaMaxHeight, drawAreaBox);

            polygonsContainer = new PolygonsContainer(drawArea, drawAreaBox);

            polygonsContainer.AddMockedPolygon();
        }
Example #5
0
 public void TryDrawLink(System.Drawing.Point currentPoint, System.Drawing.Graphics graphics, PolygonsContainer data)
 {
     NullablePoint linkPoint = isNearVertex(currentPoint, data.GetAllPoints());
     if (linkPoint != null)
     {
         graphics.DrawRectangle(new System.Drawing.Pen(POINT_LINK_COLOR, POINT_LINK_LINE_WIDTH),
             linkPoint.X - POINT_LINK_RECT_WIDTH / 2,
             linkPoint.Y - POINT_LINK_RECT_WIDTH / 2,
             POINT_LINK_RECT_WIDTH, POINT_LINK_RECT_WIDTH);
     }
 }
Example #6
0
        public static PolygonsContainer Build(Vector2[][] obstacles)
        {
            Vector2 bottomLeft = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 topRight   = new Vector2(float.MinValue, float.MinValue);

            Polygon[] polygons = new Polygon[obstacles.Length];
            for (var i = 0; i < obstacles.Length; i++)
            {
                var obstacle = obstacles[i];
                var polygon  = new Polygon(obstacle);
                if (polygon.MinX < bottomLeft.x)
                {
                    bottomLeft.x = polygon.MinX;
                }

                if (polygon.MinY < bottomLeft.y)
                {
                    bottomLeft.y = polygon.MinY;
                }

                if (polygon.MaxX > topRight.x)
                {
                    topRight.x = polygon.MaxX;
                }

                if (polygon.MaxY > topRight.y)
                {
                    topRight.y = polygon.MaxY;
                }

                polygons[i] = polygon;
            }

            var result = new PolygonsContainer(bottomLeft, topRight, null);

            result.InitializeChildren(polygons);
            return(result);
        }
Example #7
0
 public NullablePoint GetLinkPoint(System.Drawing.Point currentPoint, System.Drawing.Graphics graphics, PolygonsContainer data)
 {
     return isNearVertex(currentPoint, data.GetAllPoints());
 }
Example #8
0
 public Finder(PolygonsContainer map)
 {
     this.map = map;
 }