pub fn layout_reingold_tilford(
graph: &Graph,
root: Option<VertexId>,
mode: RtMode,
) -> IgraphResult<Vec<[f64; 2]>>Expand description
Compute the Reingold-Tilford tree layout.
Places vertices in a layered hierarchy with the root at level 0. Y-coordinate is the depth in the tree; X-coordinate is computed using the contour-merging algorithm to keep subtrees compact.
If the graph is not a tree, a BFS spanning tree from root is used.
Unreachable vertices are connected to the root before layout.
§Arguments
graph— input graph.root— root vertex for the tree layout. IfNone, automatically selects the vertex with highest degree.mode— edge traversal direction.
Returns (x, y) pairs for each vertex.
§Examples
use rust_igraph::{Graph, layout_reingold_tilford, RtMode};
// Binary tree: 0 -> {1, 2}, 1 -> {3, 4}
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(1, 4).unwrap();
let pos = layout_reingold_tilford(&g, Some(0), RtMode::All).unwrap();
assert_eq!(pos.len(), 5);
// Root should be at level 0
assert!((pos[0][1]).abs() < 1e-10);