Compare commits
No commits in common. "9bb2f4c20d67399b9700642e61222744b2fb7365" and "f3167ac12d9c35f356db5985222574531d805d80" have entirely different histories.
9bb2f4c20d
...
f3167ac12d
25
src/voxel.rs
25
src/voxel.rs
@ -1,4 +1,4 @@
|
|||||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
#[derive(Clone, Copy)]
|
||||||
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,24 +38,3 @@ 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