Skip to main content

spin_sim/geometry/
offsets.rs

1/// Hypercubic neighbor offsets: one unit vector per dimension.
2///
3/// For `n_dims = 3` this returns `[[1,0,0], [0,1,0], [0,0,1]]`.
4pub fn hypercubic(n_dims: usize) -> Vec<Vec<isize>> {
5    (0..n_dims)
6        .map(|d| {
7            let mut v = vec![0isize; n_dims];
8            v[d] = 1;
9            v
10        })
11        .collect()
12}
13
14/// Triangular-lattice neighbor offsets (2D only).
15///
16/// Returns `[[1,0], [0,1], [1,-1]]` — three forward directions giving
17/// coordination number 6.
18pub fn triangular() -> Vec<Vec<isize>> {
19    vec![vec![1, 0], vec![0, 1], vec![1, -1]]
20}