Skip to main content

layout_gem

Function layout_gem 

Source
pub fn layout_gem(
    graph: &Graph,
    seed: Option<&[[f64; 2]]>,
    params: &GemParams,
) -> IgraphResult<Vec<[f64; 2]>>
Expand description

Compute the GEM force-directed layout.

Places vertices using adaptive per-vertex temperatures with gravitational pull toward the barycenter, repulsive forces between all vertex pairs, and attractive spring forces along edges.

Edge directions are ignored (treated as undirected).

§Arguments

  • graph — input graph.
  • seed — optional initial positions. If None, random positions are generated.
  • params — algorithm parameters (use GemParams::for_graph(n) for sensible defaults).

Returns [x, y] positions for each vertex.

§Errors

Returns InvalidArgument if temperatures violate temp_min <= temp_init <= temp_max, any temperature is non-positive, or seed length doesn’t match vertex count.

§Examples

use rust_igraph::{Graph, layout_gem, GemParams};

let mut g = Graph::with_vertices(6);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(4, 5).unwrap();
g.add_edge(5, 0).unwrap();

let params = GemParams::for_graph(6);
let pos = layout_gem(&g, None, &params).unwrap();
assert_eq!(pos.len(), 6);
assert!(pos.iter().all(|p| p[0].is_finite() && p[1].is_finite()));