Skip to main content

triangular_lattice

Function triangular_lattice 

Source
pub fn triangular_lattice(
    dims: &[u32],
    directed: bool,
    mutual: bool,
) -> IgraphResult<Graph>
Expand description

Build a triangular lattice with the requested shape.

See the module documentation for the meaning of dims, directed, and mutual.

§Errors

  • IgraphError::InvalidArgument — when:
    • dims.len() is not in {1, 2, 3} (the C IGRAPH_EINVAL: "size of dimension vector must be 1, 2 or 3" path),
    • the implied vertex or edge count overflows u32.

The upstream “negative dimension” path is eliminated at the type level by taking &[u32].

§Examples

use rust_igraph::triangular_lattice;

// Triangle with side 5: 1 + 2 + 3 + 4 + 5 = 15 vertices.
let g = triangular_lattice(&[5], false, false).unwrap();
assert_eq!(g.vcount(), 15);
assert_eq!(g.ecount(), 30);

// 2 x 2 "rectangle": four vertices, five edges (matches python-igraph).
let g = triangular_lattice(&[2, 2], false, false).unwrap();
assert_eq!(g.vcount(), 4);
assert_eq!(g.ecount(), 5);

// A zero in any coordinate collapses to the empty graph.
let g = triangular_lattice(&[3, 0], false, false).unwrap();
assert_eq!(g.vcount(), 0);