pub fn layout_align(graph: &Graph, layout: &mut [Vec<f64>]) -> IgraphResult<()>Expand description
Align a graph layout with the coordinate axes.
Centers vertex positions on the origin and rotates them so that the layout’s principal axes (computed from the nematic tensor of edge directions) coincide with the coordinate axes. After rotation, axes are reordered so the widest extent is in column 0.
The layout is modified in place. Each inner Vec represents one
vertex’s coordinates; all must have the same length (dim ≥ 1).
§Errors
Returns InvalidArgument if:
layout.len()does not equalgraph.vcount().- Any coordinate vector differs in length from the first.
dim == 0(zero-dimensional coordinates).
§Examples
use rust_igraph::{Graph, layout_align};
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
// Arbitrary 2D positions
let mut layout = vec![vec![1.0, 2.0], vec![3.0, 4.0], vec![5.0, 6.0]];
layout_align(&g, &mut layout).unwrap();
// After alignment, the center of mass is at the origin
let cx: f64 = layout.iter().map(|p| p[0]).sum::<f64>() / 3.0;
let cy: f64 = layout.iter().map(|p| p[1]).sum::<f64>() / 3.0;
assert!((cx).abs() < 1e-10);
assert!((cy).abs() < 1e-10);