Compare commits
2 Commits
f3167ac12d
...
9bb2f4c20d
Author | SHA1 | Date | |
---|---|---|---|
9bb2f4c20d | |||
72ebb412f0 |
25
src/voxel.rs
25
src/voxel.rs
@ -1,4 +1,4 @@
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||
struct Voxel {
|
||||
r: u8,
|
||||
g: u8,
|
||||
@ -17,7 +17,7 @@ struct VoxelMap {
|
||||
impl VoxelMap {
|
||||
fn new(width: usize, height: usize, depth: usize) -> Self {
|
||||
Self {
|
||||
data: vec![AIR_VOXEL, width * height * depth],
|
||||
data: vec![AIR_VOXEL; width * height * depth],
|
||||
width,
|
||||
height,
|
||||
depth
|
||||
@ -38,3 +38,24 @@ impl VoxelMap {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_voxel_map() {
|
||||
let mut map = VoxelMap::new(10, 10, 10);
|
||||
map.set(0, 0, 0, Voxel { r: 255, g: 0, b: 0 });
|
||||
assert_eq!(map.get(0, 0, 0), Voxel { r: 255, g: 0, b: 0 });
|
||||
assert_eq!(map.get(1, 0, 0), AIR_VOXEL);
|
||||
assert_eq!(map.get(0, 1, 0), AIR_VOXEL);
|
||||
assert_eq!(map.get(0, 0, 1), AIR_VOXEL);
|
||||
assert_eq!(map.get(10, 0, 0), AIR_VOXEL);
|
||||
assert_eq!(map.get(0, 10, 0), AIR_VOXEL);
|
||||
assert_eq!(map.get(0, 0, 10), AIR_VOXEL);
|
||||
|
||||
// out of bounds
|
||||
assert_eq!(map.get(0, 0, 11), AIR_VOXEL);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user