Skip to main content

Module hexagonal_lattice

Module hexagonal_lattice 

Source
Expand description

Hexagonal lattice constructor (ALGO-CN-024).

Counterpart of igraph_hexagonal_lattice() in references/igraph/src/constructors/lattices.c:572-616.

Builds a planar hexagonal (honeycomb) lattice whose vertices have coordinates (i, j) for non-negative integers, with (i, j) joined to (i + 1, j) and (when i is odd) also to (i - 1, j + 1). The graph is the planar dual of crate::triangular_lattice: 1:1 correspondence between length-6 cycles here and triangles there. Every vertex has degree at most 3.

The dims slice doubles as a shape selector with three modes:

  • [n] — triangular outline, n hexagons per side
  • [size_x, size_y] — quasi-rectangle, size_x × size_y hexagons
  • [size_x, size_y, size_z] — hexagonal outline with the three sides carrying size_x, size_y, size_z hexagons respectively

Vertices are numbered lexicographically with the second coordinate more significant, matching the upstream lex_ordering = false path.

Modes:

  • directed = false: every undirected lattice edge is emitted once.
  • directed = true, mutual = false: each lattice edge becomes a single arc from the lower id to the higher.
  • directed = true, mutual = true: every undirected lattice edge becomes a pair of opposite arcs.

Special cases:

  • Any dims[k] == 0 → empty graph (upstream igraph_vector_int_any_smaller(dims, 1) guard).
  • dims.len() != 1, 2, 3IgraphError::InvalidArgument.

Algorithm: byte-for-byte port of upstream’s three private shape helpers (hexagonal_lattice_triangle_shape / hexagonal_lattice_rectangle_shape / hexagonal_lattice_hex_shape) followed by the shared hexagonal_lattice emitter, which walks every site and emits the two candidate forward neighbours (right, and — only for odd k — up-left).

Time complexity: O(|V| + |E|).

Functions§

hexagonal_lattice
Build a hexagonal (honeycomb) lattice with the requested shape.