Compare commits

...

2 Commits

Author SHA1 Message Date
9bb2f4c20d Merge remote-tracking branch 'origin/feature/voxel_container' into feature/voxel_container
# Conflicts:
#	src/voxel.rs
2023-09-16 09:01:02 +02:00
72ebb412f0 Added voxel and voxel map definitions 2023-09-16 09:00:42 +02:00

View File

@ -1,4 +1,4 @@
#[derive(Clone, Copy)] #[derive(PartialEq, Clone, Copy, Debug)]
struct Voxel { struct Voxel {
r: u8, r: u8,
g: u8, g: u8,
@ -17,7 +17,7 @@ struct VoxelMap {
impl VoxelMap { impl VoxelMap {
fn new(width: usize, height: usize, depth: usize) -> Self { fn new(width: usize, height: usize, depth: usize) -> Self {
Self { Self {
data: vec![AIR_VOXEL, width * height * depth], data: vec![AIR_VOXEL; width * height * depth],
width, width,
height, height,
depth 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);
}
}