pub fn square_lattice(
dim: &[u32],
nei: u32,
directed: bool,
mutual: bool,
periodic: Option<&[bool]>,
) -> IgraphResult<Graph>Expand description
Build a d-dimensional square lattice graph.
Returns a graph on Π dim[k] vertices arranged on a multi-dimensional
grid, with edges joining vertices that are one step apart along any
single axis. periodic (when supplied) selects which dimensions
wrap around (torus mode).
§Parameters
dim— per-dimension cardinalities. Empty slice is the zero-dimensional case (singleton).nei— neighbour-distance radius. Only0and1are supported in this initial port (higher values requireigraph_connect_neighborhood, a separate AWU).directed— whether to produce a directed graph.mutual— whendirected, emit both directions of every edge. Ignored whendirected == false.periodic— optional per-dimension wrap-around flags. Must have the same length asdimwhen supplied; otherwise treat all dimensions as non-periodic.
§Errors
IgraphError::InvalidArgument—nei >= 2(not yet supported),- length of
periodicdoes not matchdim, - vertex count
Π dim[k]overflowsu32.
§Examples
use rust_igraph::square_lattice;
// 3 × 3 grid: 9 vertices, 12 edges, 2D bounded.
let g = square_lattice(&[3, 3], 1, false, false, None).unwrap();
assert_eq!(g.vcount(), 9);
assert_eq!(g.ecount(), 12);
// 3 × 3 torus: same vertex count, 18 edges (each cell contributes
// one forward edge per dim).
let g = square_lattice(&[3, 3], 1, false, false, Some(&[true, true])).unwrap();
assert_eq!(g.vcount(), 9);
assert_eq!(g.ecount(), 18);