pub fn layout_kamada_kawai(
graph: &Graph,
weights: Option<&[f64]>,
params: &KkParams,
bounds: Option<&KkBounds>,
) -> IgraphResult<Vec<[f64; 2]>>Expand description
Compute 2D Kamada-Kawai layout.
Places vertices so that graph-theoretic distance is reflected in Euclidean distance. Works well for small-to-medium graphs (O(V²) memory for distance matrices).
§Arguments
graph— input graph (treated as undirected for shortest paths).weights— optional edge weights interpreted as edge lengths (higher weight → vertices farther apart). Must be positive.params— algorithm parameters; useKkParams::default_forfor reasonable defaults.bounds— optional per-vertex coordinate bounds.
§Examples
use rust_igraph::{Graph, layout_kamada_kawai, KkParams};
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 0).unwrap();
let params = KkParams::default_for(4);
let pos = layout_kamada_kawai(&g, None, ¶ms, None).unwrap();
assert_eq!(pos.len(), 4);