Skip to main content

rust_robotics_planning/
grid_nalgebra.rs

1// grid map definition
2// author:Salah Eddine Ghamri (s.ghamri)
3
4use std::ops::Deref;
5
6pub struct Map {
7    grid: nalgebra::DMatrix<i32>,
8}
9
10impl Map {
11    pub fn new(
12        original_matrix: nalgebra::DMatrix<i32>,
13        scale: usize,
14    ) -> Result<Self, &'static str> {
15        if scale < 1 {
16            return Err("scale must be >= 1");
17        }
18        let grid = original_matrix.kronecker(&nalgebra::DMatrix::<i32>::repeat(scale, scale, 1));
19        Ok(Self { grid })
20    }
21}
22
23impl Deref for Map {
24    type Target = nalgebra::DMatrix<i32>;
25
26    fn deref(&self) -> &Self::Target {
27        &self.grid
28    }
29}