rust/vec2d/src/lib.rs
author unC0Rr
Tue, 28 Jan 2025 15:49:45 +0100
changeset 16073 5d302b12d837
parent 15915 8f093b1b18bc
permissions -rw-r--r--
- Update landgen to use the latest rand crate - Change Size width and height from usize to u32 for portability - Implement backtracking in wfc generator
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
     1
use integral_geometry::Size;
14207
bb2f301d4fe0 2018ize everything
alfadur
parents: 14170
diff changeset
     2
use std::{
bb2f301d4fe0 2018ize everything
alfadur
parents: 14170
diff changeset
     3
    ops::{Index, IndexMut},
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
     4
    slice::SliceIndex,
14207
bb2f301d4fe0 2018ize everything
alfadur
parents: 14170
diff changeset
     5
};
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
     6
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
     7
#[derive(Debug, Clone)]
13916
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
     8
pub struct Vec2D<T> {
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
     9
    data: Vec<T>,
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    10
    size: Size,
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    11
}
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    12
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    13
impl<T> Index<usize> for Vec2D<T> {
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    14
    type Output = [T];
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    15
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    16
    #[inline]
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    17
    fn index(&self, row: usize) -> &[T] {
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    18
        debug_assert!(row < self.height());
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    19
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    20
        let pos = row * self.width();
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    21
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    22
        &self.data[pos..pos + self.width()]
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    23
    }
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    24
}
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    25
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    26
impl<T> IndexMut<usize> for Vec2D<T> {
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    27
    #[inline]
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    28
    fn index_mut(&mut self, row: usize) -> &mut [T] {
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    29
        debug_assert!(row < self.height());
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    30
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    31
        let pos = row * self.width();
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    32
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    33
        &mut self.data[pos..pos + self.size.width as usize]
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    34
    }
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    35
}
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    36
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    37
impl<T> Vec2D<T> {
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    38
    #[inline]
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    39
    pub fn width(&self) -> usize {
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    40
        self.size.width as usize
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    41
    }
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    42
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    43
    #[inline]
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    44
    pub fn height(&self) -> usize {
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    45
        self.size.height as usize
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    46
    }
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    47
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    48
    #[inline]
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    49
    pub fn size(&self) -> Size {
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    50
        self.size
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    51
    }
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    52
}
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    53
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
    54
impl<T: Copy> Vec2D<T> {
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    55
    pub fn new(size: &Size, value: T) -> Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    56
        Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    57
            size: *size,
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    58
            data: vec![value; size.area() as usize],
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    59
        }
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
    60
    }
13916
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
    61
14160
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    62
    #[inline]
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    63
    pub fn as_slice(&self) -> &[T] {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    64
        self.data.as_slice()
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    65
    }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    66
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    67
    #[inline]
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    68
    pub fn as_mut_slice(&mut self) -> &mut [T] {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
    69
        self.data.as_mut_slice()
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14032
diff changeset
    70
    }
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14032
diff changeset
    71
13916
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
    72
    #[inline]
13930
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
    73
    pub fn get(&self, row: usize, column: usize) -> Option<&<usize as SliceIndex<[T]>>::Output> {
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    74
        if row < self.height() && column < self.width() {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    75
            Some(unsafe { self.data.get_unchecked(row * self.width() + column) })
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    76
        } else {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    77
            None
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    78
        }
13930
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
    79
    }
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
    80
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
    81
    #[inline]
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    82
    pub fn get_mut(
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    83
        &mut self,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    84
        row: usize,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    85
        column: usize,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    86
    ) -> Option<&mut <usize as SliceIndex<[T]>>::Output> {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    87
        if row < self.height() && column < self.width() {
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    88
            Some(unsafe {
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    89
                self.data
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    90
                    .get_unchecked_mut(row * self.size.width as usize + column)
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
    91
            })
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    92
        } else {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    93
            None
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    94
        }
13916
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
    95
    }
13924
a140f28decc4 Implement Land2D::fill() + tests
unc0rr
parents: 13916
diff changeset
    96
a140f28decc4 Implement Land2D::fill() + tests
unc0rr
parents: 13916
diff changeset
    97
    #[inline]
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    98
    pub unsafe fn get_unchecked(
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    99
        &self,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   100
        row: usize,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   101
        column: usize,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   102
    ) -> &<usize as SliceIndex<[T]>>::Output {
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
   103
        self.data.get_unchecked(row * self.width() + column)
13930
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
   104
    }
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
   105
5c9d963492bf Implement get_unchecked* functions for Vec2D
unc0rr
parents: 13924
diff changeset
   106
    #[inline]
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   107
    pub unsafe fn get_unchecked_mut(
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   108
        &mut self,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   109
        row: usize,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   110
        column: usize,
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   111
    ) -> &mut <usize as SliceIndex<[T]>>::Output {
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
   112
        self.data
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
   113
            .get_unchecked_mut(row * self.size.width as usize + column)
13924
a140f28decc4 Implement Land2D::fill() + tests
unc0rr
parents: 13916
diff changeset
   114
    }
14030
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 13930
diff changeset
   115
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 13930
diff changeset
   116
    #[inline]
14170
a4c1a2d0ac24 implement basic land bordering
alfadur
parents: 14160
diff changeset
   117
    pub fn rows(&self) -> impl DoubleEndedIterator<Item = &[T]> {
14350
31717e1436cd recruit some newly stabilized functions
alfadur
parents: 14207
diff changeset
   118
        self.data.chunks_exact(self.width())
14030
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 13930
diff changeset
   119
    }
14160
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   120
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   121
    #[inline]
14170
a4c1a2d0ac24 implement basic land bordering
alfadur
parents: 14160
diff changeset
   122
    pub fn rows_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut [T]> {
14160
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   123
        let width = self.width();
14350
31717e1436cd recruit some newly stabilized functions
alfadur
parents: 14207
diff changeset
   124
        self.data.chunks_exact_mut(width)
14160
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   125
    }
14702
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   126
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   127
    #[inline]
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   128
    pub unsafe fn as_bytes(&self) -> &[u8] {
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   129
        use std::{mem, slice};
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 14702
diff changeset
   130
14702
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   131
        slice::from_raw_parts(
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   132
            self.data.as_ptr() as *const u8,
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   133
            self.data.len() * mem::size_of::<T>(),
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   134
        )
29dbe9ce8b7d add basic map rendering with gl
fkaa
parents: 14350
diff changeset
   135
    }
14160
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   136
}
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   137
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   138
impl<T: Copy> AsRef<[T]> for Vec2D<T> {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   139
    fn as_ref(&self) -> &[T] {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   140
        self.as_slice()
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   141
    }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   142
}
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   143
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   144
impl<T: Copy> AsMut<[T]> for Vec2D<T> {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   145
    fn as_mut(&mut self) -> &mut [T] {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   146
        self.as_mut_slice()
c24a76f131d6 implement basic land texturing
alfadur
parents: 14121
diff changeset
   147
    }
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   148
}
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   149
15915
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   150
impl<T: Clone> Vec2D<T> {
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   151
    pub fn from_iter<I: IntoIterator<Item = T>>(iter: I, size: &Size) -> Option<Vec2D<T>> {
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   152
        let data: Vec<T> = iter.into_iter().collect();
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
   153
        if size.width as usize * size.height as usize == data.len() {
15915
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   154
            Some(Vec2D { data, size: *size })
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   155
        } else {
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   156
            None
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   157
        }
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   158
    }
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   159
}
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15913
diff changeset
   160
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   161
#[cfg(test)]
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   162
mod tests {
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   163
    use super::*;
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   164
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   165
    #[test]
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   166
    fn basics() {
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
   167
        let mut v: Vec2D<u8> = Vec2D::new(&Size::new(2, 3), 0xff);
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   168
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
   169
        assert_eq!(v.width(), 2);
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14030
diff changeset
   170
        assert_eq!(v.height(), 3);
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   171
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   172
        assert_eq!(v[0][0], 0xff);
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   173
        assert_eq!(v[2][1], 0xff);
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   174
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   175
        v[2][1] = 0;
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   176
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   177
        assert_eq!(v[2][0], 0xff);
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   178
        assert_eq!(v[2][1], 0);
13916
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
   179
16073
5d302b12d837 - Update landgen to use the latest rand crate
unC0Rr
parents: 15915
diff changeset
   180
        v.get_mut(2, 1).into_iter().for_each(|v| *v = 1);
13916
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
   181
        assert_eq!(v[2][1], 1);
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
   182
cd437d76978a Add get_mut() to Vec2D
unc0rr
parents: 13915
diff changeset
   183
        assert_eq!(v.get_mut(2, 2), None);
13911
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   184
    }
fa9f93393e9c Implement vec2d library to use for land arrays in the future
unc0rr
parents:
diff changeset
   185
}