Skip to main content

murk_space/
edge.rs

1//! Spatial edge (boundary) behavior for lattice backends.
2
3/// How a lattice space handles neighbors at its edges.
4///
5/// This is distinct from [`murk_core::BoundaryBehavior`], which controls
6/// field *value* clamping. `EdgeBehavior` controls the *topology* — which
7/// cells are considered neighbors of boundary cells.
8///
9/// # Examples
10///
11/// ```
12/// use murk_space::{Square4, EdgeBehavior, Space};
13///
14/// // Absorb: corner has 2 neighbors, interior has 4.
15/// let absorb = Square4::new(4, 4, EdgeBehavior::Absorb).unwrap();
16/// let corner: murk_core::Coord = vec![0i32, 0].into();
17/// let interior: murk_core::Coord = vec![1i32, 1].into();
18/// assert_eq!(absorb.neighbours(&corner).len(), 2);
19/// assert_eq!(absorb.neighbours(&interior).len(), 4);
20///
21/// // Wrap: all cells have exactly 4 neighbors (torus).
22/// let wrap = Square4::new(4, 4, EdgeBehavior::Wrap).unwrap();
23/// assert_eq!(wrap.neighbours(&corner).len(), 4);
24/// ```
25#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
26pub enum EdgeBehavior {
27    /// Out-of-bounds neighbor maps to the boundary cell (self-loop).
28    Clamp,
29    /// Out-of-bounds neighbor wraps to the opposite side (periodic).
30    Wrap,
31    /// Out-of-bounds neighbor is omitted (fewer neighbors at edges).
32    Absorb,
33}