Delaunay.Voronoi.SpanningTree C# (CSharp) Method

SpanningTree() public method

public SpanningTree ( KruskalType type = KruskalType.MINIMUM ) : List
type KruskalType
return List
		public List<LineSegment> SpanningTree (KruskalType type = KruskalType.MINIMUM/*, BitmapData keepOutMask = null*/)
		{
			List<Edge> edges = DelaunayHelpers.SelectNonIntersectingEdges (/*keepOutMask,*/_edges);
			List<LineSegment> segments = DelaunayHelpers.DelaunayLinesForEdges (edges);
			return DelaunayHelpers.Kruskal (segments, type);
		}

Usage Example

Example #1
0
    // take all the midpoints of the selected rooms and feed that into the Delaunay procedure
    //  generate a graph, also it's good to have ID for rooms
    // and generate minimum spanning tree
    private void TriangulateMainRoomsMidpointsAndGenerateMST()
    {
        List <Vector2> midpoints = new List <Vector2>();
        List <uint>    colors    = new List <uint>(); // Colors are just necessary part for choosen delaunay library

        Vector2 min = Vector2.positiveInfinity;
        Vector2 max = Vector2.zero;

        for (int i = 0; i < rooms.Count; i++)
        {
            DelaunayMSTRoom room = rooms[i];
            if (room.isMainRoom)
            {
                colors.Add(0);
                midpoints.Add(new Vector2(room.x + room.width / 2, room.y + room.height / 2)); // use division (not multiplication) because we need INT value (or use RoundToInt)
                min.x = Mathf.Min(min.x, room.x);
                min.y = Mathf.Min(min.y, room.y);

                max.x = Mathf.Max(max.x, room.x);
                max.y = Mathf.Max(max.y, room.y);
            }
        }

        Delaunay.Voronoi voronoi = new Delaunay.Voronoi(midpoints, colors, new Rect(min.x, min.y, max.x, max.y));
        delaunayLines = voronoi.DelaunayTriangulation();                   // Triangulate main rooms

        spanningTree = voronoi.SpanningTree(Delaunay.KruskalType.MINIMUM); //Find min. span. tree

        if (settings.isDebugLogEnabled)
        {
            Debug.Log("Main passages count: " + spanningTree.Count);
        }
    }
All Usage Examples Of Delaunay.Voronoi::SpanningTree