From 243263fecdbab0d281edf9b92a73a401286979da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Korg=C3=B3l?= <kpiotr2005@gmail.com> Date: Sun, 12 Jan 2020 15:45:20 +0100 Subject: [PATCH] Improvement: Replace all '..=b' with '..b + 1' --- client/src/lib.rs | 4 ++-- common/src/region.rs | 4 ++-- common/src/sys/phys.rs | 6 ++++-- common/src/volumes/vol_grid_2d.rs | 4 ++-- common/src/volumes/vol_grid_3d.rs | 6 +++--- server/src/lib.rs | 2 +- voxygen/src/menu/main/client_init.rs | 2 +- world/src/sim/mod.rs | 4 ++-- world/src/sim/util.rs | 2 +- 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index d9691c9ed1..1f20cc1227 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -411,7 +411,7 @@ impl Client { // Request chunks from the server. let mut all_loaded = true; - 'outer: for dist in 0..=view_distance as i32 { + 'outer: for dist in 0..(view_distance as i32) + 1 { // Only iterate through chunks that need to be loaded for circular vd // The (dist - 2) explained: // -0.5 because a chunk is visible if its corner is within the view distance @@ -428,7 +428,7 @@ impl Client { dist }; - for i in -top..=top { + for i in -top..top + 1 { let keys = [ chunk_pos + Vec2::new(dist, i), chunk_pos + Vec2::new(i, dist), diff --git a/common/src/region.rs b/common/src/region.rs index 2725f6fb47..295c86dc44 100644 --- a/common/src/region.rs +++ b/common/src/region.rs @@ -372,8 +372,8 @@ pub fn regions_in_vd(pos: Vec3<f32>, vd: f32) -> HashSet<Vec2<i32>> { let max = RegionMap::pos_key(pos_xy.map(|e| (e + vd_extended) as i32)); let min = RegionMap::pos_key(pos_xy.map(|e| (e - vd_extended) as i32)); - for x in min.x..=max.x { - for y in min.y..=max.y { + for x in min.x..max.x + 1 { + for y in min.y..max.y + 1 { let key = Vec2::new(x, y); if region_in_vd(key, pos, vd) { diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 67689495b4..955d229c22 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -110,8 +110,10 @@ impl<'a> System<'a> for Sys { let hdist = player_rad.ceil() as i32; let vdist = player_height.ceil() as i32; // Neighbouring blocks iterator - let near_iter = (-hdist..=hdist) - .map(move |i| (-hdist..=hdist).map(move |j| (0..=vdist).map(move |k| (i, j, k)))) + let near_iter = (-hdist..hdist + 1) + .map(move |i| { + (-hdist..hdist + 1).map(move |j| (0..vdist + 1).map(move |k| (i, j, k))) + }) .flatten() .flatten(); diff --git a/common/src/volumes/vol_grid_2d.rs b/common/src/volumes/vol_grid_2d.rs index 00e21a19aa..ac97fb5738 100644 --- a/common/src/volumes/vol_grid_2d.rs +++ b/common/src/volumes/vol_grid_2d.rs @@ -69,8 +69,8 @@ impl<I: Into<Aabr<i32>>, V: RectRasterableVol + ReadVol + Debug> SampleVol<I> fo let mut sample = VolGrid2d::new()?; let chunk_min = Self::chunk_key(range.min); let chunk_max = Self::chunk_key(range.max); - for x in chunk_min.x..=chunk_max.x { - for y in chunk_min.y..=chunk_max.y { + for x in chunk_min.x..chunk_max.x + 1 { + for y in chunk_min.y..chunk_max.y + 1 { let chunk_key = Vec2::new(x, y); let chunk = self.get_key_arc(chunk_key).cloned(); diff --git a/common/src/volumes/vol_grid_3d.rs b/common/src/volumes/vol_grid_3d.rs index 627d1aeb42..8d8dfc84c4 100644 --- a/common/src/volumes/vol_grid_3d.rs +++ b/common/src/volumes/vol_grid_3d.rs @@ -73,9 +73,9 @@ impl<I: Into<Aabb<i32>>, V: RasterableVol + ReadVol + Debug> SampleVol<I> for Vo let mut sample = VolGrid3d::new()?; let chunk_min = Self::chunk_key(range.min); let chunk_max = Self::chunk_key(range.max); - for x in chunk_min.x..=chunk_max.x { - for y in chunk_min.y..=chunk_max.y { - for z in chunk_min.z..=chunk_max.z { + for x in chunk_min.x..chunk_max.x + 1 { + for y in chunk_min.y..chunk_max.y + 1 { + for z in chunk_min.z..chunk_max.z + 1 { let chunk_key = Vec3::new(x, y, z); let chunk = self.get_key_arc(chunk_key).cloned(); diff --git a/server/src/lib.rs b/server/src/lib.rs index 2a5147ad1f..6a1575c772 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -132,7 +132,7 @@ impl Server { // until the first air block is found // (up to max_z + 1, because max_z could still be a soild block) // if no air block is found default to max_z + 1 - let z = (min_z..=max_z + 1) + let z = (min_z..(max_z + 1) + 1) .find(|z| { block_sampler .get_with_z_cache( diff --git a/voxygen/src/menu/main/client_init.rs b/voxygen/src/menu/main/client_init.rs index 557dc715d3..5ebcf4526e 100644 --- a/voxygen/src/menu/main/client_init.rs +++ b/voxygen/src/menu/main/client_init.rs @@ -51,7 +51,7 @@ impl ClientInit { let mut last_err = None; - 'tries: for _ in 0..=60 { + 'tries: for _ in 0..60 + 1 { // 300 Seconds if cancel2.load(Ordering::Relaxed) { break; diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 8735ad135b..bc58f926a7 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -454,8 +454,8 @@ impl WorldSim { _ => {} } */ let pos = uniform_idx_as_vec2(posi); - for x in pos.x - 1..=pos.x + 1 { - for y in pos.y - 1..=pos.y + 1 { + for x in pos.x - 1..(pos.x + 1) + 1 { + for y in pos.y - 1..(pos.y + 1) + 1 { if x >= 0 && y >= 0 && x < WORLD_SIZE.x as i32 && y < WORLD_SIZE.y as i32 { let posi = vec2_as_uniform_idx(Vec2::new(x, y)); if !is_underwater(posi) { diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index 252dc68050..c88cdcdc1e 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -101,7 +101,7 @@ pub fn cdf_irwin_hall<const N: usize>(weights: &[f32; N], samples: [f32; N]) -> y /= weights.iter().product::<f32>(); // Remember to multiply by 1 / N! at the end. - y / (1..=N as i32).product::<i32>() as f32 + y / (1..(N as i32) + 1).product::<i32>() as f32 } /// First component of each element of the vector is the computed CDF of the noise function at this