pub trait GridPointIndex {
// Required methods
fn grid_shape(&self) -> (usize, usize);
fn scanning_mode(&self) -> &ScanningMode;
// Provided method
fn ij(&self) -> Result<GridPointIndexIterator, GribError> { ... }
}Expand description
A functionality to generate an iterator over 2D index (i, j) of grid
points.
§Examples
use grib::{GridPointIndex, def::grib2::template::param_set::ScanningMode};
struct Grid {
ni: u32,
nj: u32,
scanning_mode: ScanningMode,
}
impl GridPointIndex for Grid {
fn grid_shape(&self) -> (usize, usize) {
(self.ni as usize, self.nj as usize)
}
fn scanning_mode(&self) -> &ScanningMode {
&self.scanning_mode
}
}
let grid_2x3 = Grid {
ni: 2,
nj: 3,
scanning_mode: ScanningMode(0b01000000),
};
assert_eq!(grid_2x3.grid_shape(), (2, 3));
let mut iter = grid_2x3.ij().unwrap();
assert_eq!(iter.next(), Some((0, 0)));
assert_eq!(iter.next(), Some((1, 0)));
assert_eq!(iter.next(), Some((0, 1)));
assert_eq!(iter.next(), Some((1, 1)));
assert_eq!(iter.next(), Some((0, 2)));
assert_eq!(iter.next(), Some((1, 2)));
assert_eq!(iter.next(), None);Required Methods§
Sourcefn grid_shape(&self) -> (usize, usize)
fn grid_shape(&self) -> (usize, usize)
Returns the shape of the grid, i.e. a tuple of the number of grids in the i and j directions.
Sourcefn scanning_mode(&self) -> &ScanningMode
fn scanning_mode(&self) -> &ScanningMode
Returns ScanningMode used for the iteration.
Provided Methods§
Sourcefn ij(&self) -> Result<GridPointIndexIterator, GribError>
fn ij(&self) -> Result<GridPointIndexIterator, GribError>
Returns an iterator over 2D index (i, j) of grid points.