pub struct GridMeta { /* private fields */ }Implementations§
Source§impl GridMeta
impl GridMeta
pub const fn new(width: usize, height: usize) -> Self
pub fn check_dem<T>(&self, dem: &[T]) -> Result<()>
pub fn width(&self) -> usize
pub fn height(&self) -> usize
pub fn size(&self) -> usize
Sourcepub fn nshift(&self) -> &[isize; 8]
pub fn nshift(&self) -> &[isize; 8]
Offset from a focal cell’s index to its neighbours in terms of flat indexing
let arr = [
1,2,3,
0,x,4,
7,6,5
];
for i in 0..8 {
assert!(arr[(4 + meta.nshift()[i]) as usize] == i)
}Sourcepub fn shift(&self, idx: usize, dir: u8) -> usize
pub fn shift(&self, idx: usize, dir: u8) -> usize
Offset from a focal cell’s index to its neighbours in terms of flat indexing
let arr = [
1,2,3,
0,x,4,
7,6,5
];
for i in 0..8 {
assert!(arr[meta.shift(4,i)] == i)
}Sourcepub const fn rev(n: usize) -> usize
pub const fn rev(n: usize) -> usize
Reverse the direction of nshift:
let arr = [
1,2,3,
0,x,4,
7,6,5,
];
for n in 0..8 {
let rec_idx = (4+meta.nshift()[n]) as usize;
let rec = arr[rec_idx];
assert_eq!(rec, n);
let _x = arr[(rec_idx as isize+meta.nshift()[GridMeta::rev(rec)]) as usize];
assert_eq!(_x, x);
}pub fn is_edge_cell(&self, x: usize, y: usize) -> bool
pub fn is_edge(&self, i: usize) -> bool
pub fn in_grid(&self, x: isize, y: isize) -> bool
pub fn i_to_xy(&self, i: usize) -> (usize, usize)
pub fn xy_to_i(&self, x: usize, y: usize) -> usize
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GridMeta
impl RefUnwindSafe for GridMeta
impl Send for GridMeta
impl Sync for GridMeta
impl Unpin for GridMeta
impl UnwindSafe for GridMeta
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more