From 7038180b52ba5d51026de5ecfe0d874ae85c2686 Mon Sep 17 00:00:00 2001 From: Duane King Date: Fri, 24 Nov 2023 10:42:34 -0800 Subject: [PATCH] Fix overflow, reformat that code to better show math operations --- src/chunk/systems.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chunk/systems.rs b/src/chunk/systems.rs index 0241ea6..237a066 100644 --- a/src/chunk/systems.rs +++ b/src/chunk/systems.rs @@ -133,10 +133,10 @@ pub(crate) fn cull_sides_of_mesh( let adj_chunk_grid = { chunks_query.get(adj_chunk).unwrap().grid }; for svox in iter_faces_of_chunk(dims, face) { let adj_voxel_ind = match face { - Right => svox - WIDTH + 1, - Left => svox + WIDTH - 1, - Back => svox - WIDTH * (LENGTH - 1), - Forward => svox + WIDTH * (LENGTH - 1), + Right => if svox < WIDTH {1} else {(svox - WIDTH) + 1}, + Left => (svox + WIDTH) - 1, + Back => svox - (WIDTH * (LENGTH - 1)), + Forward => svox + (WIDTH * (LENGTH - 1)), _ => panic!("Shouldn't happen"), };