Beispiel #1
0
 public void Clear()
 {
     NavObstacles.Clear();
     NavSurfaces.Clear();
     Obstacles.Clear();
     Surfaces.Clear();
 }
Beispiel #2
0
        public void Build()
        {
            NavObstacles.Clear();
            NavSurfaces.Clear();

            if (Obstacles.Count == 1 && Surfaces.Count == 0)
            {
                NavObstacles.Add(new NavShape(Obstacles.First().navElementPoints, NavElement.Type.Obstacle));
                return;
            }

            if (Obstacles.Count == 0 && Surfaces.Count > 0)
            {
                foreach (var surface in Surfaces)
                {
                    NavSurfaces.Add(new NavShape(surface.navElementPoints, NavElement.Type.Surface));
                }

                return;
            }

            List <NavElement>       obstacles          = new List <NavElement>(Obstacles);
            List <NavElement>       surfaces           = new List <NavElement>(Surfaces);
            List <List <IntPoint> > obstaclesIntPoints = new List <List <IntPoint> >();

            foreach (var obstacle in obstacles)
            {
                obstaclesIntPoints.Add(obstacle.intNavElementPoints);
            }

            if (Obstacles.Count > 0)
            {
                if (Obstacles.Count == 1)
                {
                    NavObstacles.Add(new NavShape(obstacles[0].navElementPoints, NavElement.Type.Obstacle));
                }
                else
                {
                    _Nav2D.clipper.Clear();
                    _Nav2D.polyTree.Clear();
                    _Nav2D.clipper.AddPaths(obstaclesIntPoints, PolyType.ptSubject, true);
                    _Nav2D.clipper.Execute(ClipType.ctUnion, _Nav2D.polyTree, PolyFillType.pftNonZero);

                    // We got more separated ones
                    if (_Nav2D.polyTree.IsHole)
                    {
                        foreach (var child in _Nav2D.polyTree.Childs)
                        {
                            NavObstacles.Add(new NavShape(_Nav2D, child.Contour, child.IsHole, child.Childs, null, NavElement.Type.Obstacle));
                        }
                    }
                    else // We got one big containing everyone
                    {
                        NavObstacles.Add(new NavShape(_Nav2D, _Nav2D.polyTree.Contour, false, _Nav2D.polyTree.Childs, null, NavElement.Type.Obstacle));
                    }
                }
            }

            if (surfaces.Count == 0)
            {
                return;
            }

            foreach (var surface in surfaces)
            {
                _Nav2D.clipper.Clear();
                _Nav2D.polyTree.Clear();
                _Nav2D.clipper.AddPath(surface.intNavElementPoints, PolyType.ptSubject, true);
                _Nav2D.clipper.AddPaths(obstaclesIntPoints, PolyType.ptClip, true);
                _Nav2D.clipper.Execute(ClipType.ctDifference, _Nav2D.polyTree, PolyFillType.pftNonZero);

                // We got more separated ones
                if (_Nav2D.polyTree.IsHole)
                {
                    foreach (var child in _Nav2D.polyTree.Childs)
                    {
                        NavSurfaces.Add(new NavShape(_Nav2D, child.Contour, false, null, null, NavElement.Type.Surface));
                    }
                }
                else // We got one big containing everyone
                {
                    NavSurfaces.Add(new NavShape(_Nav2D, _Nav2D.polyTree.Contour, false, null, null, NavElement.Type.Surface));
                }
            }
        }