Skip to content

Commit 66ab18e

Browse files
[RS] Wrote tests for tasks 1-7
1 parent f7fd6a9 commit 66ab18e

File tree

9 files changed

+751
-37
lines changed

9 files changed

+751
-37
lines changed

method-rs/Cargo.lock

Lines changed: 296 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

method-rs/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
2-
name = "method-rs"
2+
name = "blocks-in-3D"
33
version = "0.1.0"
44
edition = "2024"
55

6-
[dependencies]
6+
[dev-dependencies]
7+
rstest = "0.26.1"

method-rs/src/libchunk/chunk.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub const BLOCK_AIR: char = '0';
2-
pub const BLOCK_GRASS: char = '1';
3-
pub const BLOCK_WOOD: char = '2';
4-
pub const BLOCK_STONE: char = '3';
1+
pub const BLOCK_AIR: u8 = 0;
2+
pub const BLOCK_GRASS: u8 = 1;
3+
pub const BLOCK_WOOD: u8 = 2;
4+
pub const BLOCK_STONE: u8 = 3;

method-rs/src/libchunk/chunk_compress.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
fn flatten(
2-
chunk: &Vec<Vec<Vec<char>>>,
2+
chunk: &Vec<Vec<Vec<u8>>>,
33
width: usize,
44
height: usize,
55
depth: usize,
6-
) -> Vec<char> {
6+
) -> Vec<u8> {
77
let mut array = Vec::with_capacity(width * height * depth);
88

99
for y in 0..height {
@@ -16,3 +16,22 @@ fn flatten(
1616

1717
array
1818
}
19+
20+
21+
pub fn chunk_encode(
22+
chunk: &Vec<Vec<Vec<u8>>>,
23+
width: usize,
24+
height: usize,
25+
depth: usize,
26+
) -> Vec<u8> {
27+
todo!();
28+
}
29+
30+
pub fn chunk_decode(
31+
code: &Vec<u8>,
32+
width: usize,
33+
height: usize,
34+
depth: usize,
35+
) -> Vec<u8> {
36+
todo!();
37+
}

method-rs/src/libchunk/chunk_gen.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub fn is_inside(
88

99

1010
pub fn chunk_place_block(
11-
chunk: &mut Vec<Vec<Vec<char>>>,
11+
chunk: &mut Vec<Vec<Vec<u8>>>,
1212
width: usize, height: usize, depth: usize,
1313
x: usize, y: usize, z: usize,
14-
block: char
14+
block: u8
1515
) {
1616
if !is_inside(width, height, depth, x as usize, y as usize, z as usize) {
1717
return;
@@ -38,11 +38,11 @@ fn max(a: usize, b: usize) -> usize {
3838

3939

4040
pub fn chunk_fill_cuboid(
41-
chunk: &mut Vec<Vec<Vec<char>>>,
41+
chunk: &mut Vec<Vec<Vec<u8>>>,
4242
width: usize, height: usize, depth: usize,
4343
x0: usize, y0: usize, z0: usize,
4444
x1: usize, y1: usize, z1: usize,
45-
block: char
45+
block: u8
4646
) {
4747
for x in min(x0, x1)..=max(x0, x1) {
4848
for y in min(y0, y1)..=max(y0, y1) {
@@ -64,10 +64,10 @@ fn euclidian_dist(
6464
}
6565

6666
pub fn chunk_fill_sphere(
67-
chunk: &mut Vec<Vec<Vec<char>>>,
67+
chunk: &mut Vec<Vec<Vec<u8>>>,
6868
width: usize, height: usize, depth: usize,
6969
x: usize, y: usize, z: usize,
70-
radius: f32, block: char
70+
radius: f32, block: u8
7171
) {
7272
let r: usize = radius.ceil().abs() as usize;
7373

0 commit comments

Comments
 (0)