pub struct Square4 { /* private fields */ }Expand description
A two-dimensional square grid with 4-connected neighbourhood.
Each cell has coordinate [row, col] where 0 <= row < rows and
0 <= col < cols. Neighbours are the four cardinal directions
(north, south, east, west). Distance is Manhattan (L1).
Boundary handling is controlled by EdgeBehavior:
- Absorb: edge cells have fewer neighbors (corners have 2, edges have 3)
- Clamp: edge cells self-loop on the boundary axis
- Wrap: periodic boundary (torus topology)
Implementations§
Source§impl Square4
impl Square4
Sourcepub fn new(rows: u32, cols: u32, edge: EdgeBehavior) -> Result<Self, SpaceError>
pub fn new(rows: u32, cols: u32, edge: EdgeBehavior) -> Result<Self, SpaceError>
Create a new 2D grid with rows * cols cells and the given edge behavior.
Returns Err(SpaceError::EmptySpace) if either dimension is 0, or
Err(SpaceError::DimensionTooLarge) if either exceeds i32::MAX.
§Examples
use murk_space::{Square4, EdgeBehavior, Space};
let grid = Square4::new(16, 16, EdgeBehavior::Absorb).unwrap();
assert_eq!(grid.cell_count(), 256);
assert_eq!(grid.ndim(), 2);
// Neighbors of corner cell [0, 0] with Absorb: only 2 neighbors.
let coord = vec![0i32, 0].into();
assert_eq!(grid.neighbours(&coord).len(), 2);Sourcepub fn edge_behavior(&self) -> EdgeBehavior
pub fn edge_behavior(&self) -> EdgeBehavior
Edge behavior.
Trait Implementations§
Source§impl Space for Square4
impl Space for Square4
Source§fn cell_count(&self) -> usize
fn cell_count(&self) -> usize
Total number of cells in the space.
Source§fn neighbours(&self, coord: &Coord) -> SmallVec<[Coord; 8]>
fn neighbours(&self, coord: &Coord) -> SmallVec<[Coord; 8]>
Enumerate the neighbors of a cell. Read more
Source§fn max_neighbour_degree(&self) -> usize
fn max_neighbour_degree(&self) -> usize
Maximum neighbor-list length over all cells in this space. Read more
Source§fn compile_region(&self, spec: &RegionSpec) -> Result<RegionPlan, SpaceError>
fn compile_region(&self, spec: &RegionSpec) -> Result<RegionPlan, SpaceError>
Compile a region specification into a plan for O(1) lookups.
Source§fn canonical_ordering(&self) -> Vec<Coord> ⓘ
fn canonical_ordering(&self) -> Vec<Coord> ⓘ
All cells in deterministic canonical order. Read more
Source§fn canonical_rank(&self, coord: &Coord) -> Option<usize>
fn canonical_rank(&self, coord: &Coord) -> Option<usize>
Position of a coordinate in the canonical ordering. Read more
Source§fn canonical_rank_slice(&self, coord: &[i32]) -> Option<usize>
fn canonical_rank_slice(&self, coord: &[i32]) -> Option<usize>
Position of a coordinate slice in the canonical ordering. Read more
Source§fn instance_id(&self) -> SpaceInstanceId
fn instance_id(&self) -> SpaceInstanceId
Unique instance identifier for this space object. Read more
Source§fn topology_eq(&self, other: &dyn Space) -> bool
fn topology_eq(&self, other: &dyn Space) -> bool
Returns
true if self and other are topologically equivalent:
same concrete type and identical behavioral parameters. Read moreSource§fn iter_region<'a>(
&'a self,
plan: &'a RegionPlan,
) -> Box<dyn Iterator<Item = Coord> + 'a>
fn iter_region<'a>( &'a self, plan: &'a RegionPlan, ) -> Box<dyn Iterator<Item = Coord> + 'a>
Iterate over the cells in a compiled region. Read more
Source§fn map_coord_to_tensor_index(
&self,
coord: &Coord,
plan: &RegionPlan,
) -> Option<usize>
fn map_coord_to_tensor_index( &self, coord: &Coord, plan: &RegionPlan, ) -> Option<usize>
Map a coordinate to its flat tensor index within a compiled region. Read more
Auto Trait Implementations§
impl Freeze for Square4
impl RefUnwindSafe for Square4
impl Send for Square4
impl Sync for Square4
impl Unpin for Square4
impl UnsafeUnpin for Square4
impl UnwindSafe for Square4
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more