pub struct Square8 { /* private fields */ }Expand description
A two-dimensional square grid with 8-connected neighbourhood.
Each cell has coordinate [row, col]. Neighbours include the four
cardinal directions plus four diagonals. Distance is Chebyshev (L-inf),
consistent with 8-connected semantics where diagonal moves cost 1.
Boundary handling is controlled by EdgeBehavior:
- Absorb: edge cells have fewer neighbors (corners have 3, edges have 5)
- Clamp: edge cells self-loop on the boundary axis
- Wrap: periodic boundary (torus topology)
Implementations§
Source§impl Square8
impl Square8
Sourcepub const MAX_DIM: u32
pub const MAX_DIM: u32
Create a new 2D grid with rows * cols cells and the given edge behavior.
Maximum dimension size: coordinates use i32, so each axis must fit.
Sourcepub fn new(rows: u32, cols: u32, edge: EdgeBehavior) -> Result<Self, SpaceError>
pub fn new(rows: u32, cols: u32, edge: EdgeBehavior) -> Result<Self, SpaceError>
Returns Err(SpaceError::EmptySpace) if either dimension is 0, or
Err(SpaceError::DimensionTooLarge) if either exceeds i32::MAX.
Sourcepub fn edge_behavior(&self) -> EdgeBehavior
pub fn edge_behavior(&self) -> EdgeBehavior
Edge behavior.
Trait Implementations§
Source§impl Space for Square8
impl Space for Square8
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 Square8
impl RefUnwindSafe for Square8
impl Send for Square8
impl Sync for Square8
impl Unpin for Square8
impl UnsafeUnpin for Square8
impl UnwindSafe for Square8
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