public NavShape(Nav2D nav2D, List <IntPoint> points, bool hole, List <PolyNode> children, NavShape parent, NavElement.Type navType) { Points = new Vector2[points.Count]; for (int i = 0; i < Points.Length; ++i) { Points[i] = nav2D.ParseToVector2(points[i]); } Hole = hole; NavType = navType; Parent = parent; if (children == null || children.Count == 0) { Children = null; return; } Children = new List <NavShape>(); foreach (var child in children) { Children.Add(new NavShape(nav2D, child.Contour, child.IsHole, child.Childs, this, navType)); } }
private void CreateEdgePoints() { foreach (var element in elementsGroups) { for (var i = 0; i < element.NavSurfaces.Count; ++i) { NavShape surface = element.NavSurfaces[i]; HashSet <NavPoint> forbiddenConnection = new HashSet <NavPoint>(); FillTheEdgePoints(ref surface, ref forbiddenConnection); } Queue <NavShape> obstacles = new Queue <NavShape>(element.NavObstacles); Dictionary <NavShape, HashSet <NavPoint> > parentForbiddenConnection = new Dictionary <NavShape, HashSet <NavPoint> >(); while (obstacles.Count != 0) { NavShape obstacle = obstacles.Dequeue(); HashSet <NavPoint> forbiddenConnection = obstacle.Hole ? parentForbiddenConnection[obstacle.Parent] : new HashSet <NavPoint>(); FillTheEdgePoints(ref obstacle, ref forbiddenConnection); if (!obstacle.Hole) { parentForbiddenConnection.Add(obstacle, forbiddenConnection); } if (obstacle.Children == null) { continue; } foreach (var child in obstacle.Children) { obstacles.Enqueue(child); } } } }
private void FillTheEdgePoints(ref NavShape navShape, ref HashSet <NavPoint> forbiddenConnection) { NavPoint lastPoint = new NavPoint(_ConnectionOrderId++, navShape.Points[navShape.Points.Length - 1], forbiddenConnection); NavPoint previousPoint = lastPoint; for (int i = 0; i < navShape.Points.Length - 1; ++i) { NavPoint point = new NavPoint(_ConnectionOrderId++, navShape.Points[i], forbiddenConnection); _NavPoints.Add(point); point.Neighbours.Add(previousPoint); previousPoint.Neighbours.Add(point); AddToConnectionDictionary(previousPoint, point); forbiddenConnection.Add(point); previousPoint = point; } _NavPoints.Add(lastPoint); previousPoint.Neighbours.Add(lastPoint); lastPoint.Neighbours.Add(previousPoint); AddToConnectionDictionary(previousPoint, lastPoint); forbiddenConnection.Add(lastPoint); }