pub struct Hex2D { /* private fields */ }Expand description
A two-dimensional hexagonal lattice with axial coordinates.
Each cell has coordinate [q, r] where 0 <= q < cols and 0 <= r < rows.
The grid uses pointy-top orientation with six neighbours per interior cell.
Boundary behavior is Absorb (edge cells have fewer neighbours).
Distance is cube distance: max(|dq|, |dr|, |dq + dr|), which equals
the graph geodesic on the hex grid.
Canonical ordering is r-then-q: outer loop over r, inner loop over q.
§Examples
use murk_space::{Hex2D, Space};
let hex = Hex2D::new(5, 5).unwrap();
assert_eq!(hex.rows(), 5);
assert_eq!(hex.cols(), 5);
assert_eq!(hex.cell_count(), 25);
assert_eq!(hex.ndim(), 2);
// Interior cell has 6 neighbours.
let interior: murk_core::Coord = vec![2i32, 2].into();
assert_eq!(hex.neighbours(&interior).len(), 6);
// Corner cell has fewer neighbours (absorb boundary).
let corner: murk_core::Coord = vec![0i32, 0].into();
assert_eq!(hex.neighbours(&corner).len(), 2);
// Cube distance between adjacent cells is 1.
let a: murk_core::Coord = vec![2i32, 1].into();
let b: murk_core::Coord = vec![3i32, 1].into();
assert_eq!(hex.distance(&a, &b), 1.0);Implementations§
Trait Implementations§
Source§impl Space for Hex2D
impl Space for Hex2D
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 Hex2D
impl RefUnwindSafe for Hex2D
impl Send for Hex2D
impl Sync for Hex2D
impl Unpin for Hex2D
impl UnsafeUnpin for Hex2D
impl UnwindSafe for Hex2D
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