From 31fe15becbf575734a38084ad472608d7f57ec9a Mon Sep 17 00:00:00 2001 From: Stephen D Date: Sun, 27 Oct 2024 11:36:21 -0300 Subject: [PATCH] fix remaining clippys --- src/data_processing.rs | 3 +- src/element_processing/tourisms.rs | 2 +- src/element_processing/water_areas.rs | 59 ++++++++++----------------- src/osm_parser.rs | 4 +- 4 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/data_processing.rs b/src/data_processing.rs index 84944bf..4687265 100644 --- a/src/data_processing.rs +++ b/src/data_processing.rs @@ -176,8 +176,7 @@ pub fn generate_world( for z in 0..=(scale_factor_z as i32) { // Use the smaller of [current block y, ground level y] let max_y = (MIN_Y..MAX_Y) - .filter(|y| editor.block_at(x, *y, z)) - .next() + .find(|y| editor.block_at(x, *y, z)) .unwrap_or(MAX_Y) .min(GROUND_LEVEL); diff --git a/src/element_processing/tourisms.rs b/src/element_processing/tourisms.rs index 9a3c9e2..408637f 100644 --- a/src/element_processing/tourisms.rs +++ b/src/element_processing/tourisms.rs @@ -23,7 +23,7 @@ pub fn generate_tourisms(editor: &mut WorldEditor, element: &ProcessedNode, grou if tourism_type == "information" { if let Some("board") = element.tags.get("information").map(|x| x.as_str()) { // TODO draw a sign - editor.set_block(&OAK_PLANKS, x, ground_level + 1, z, None, None); + editor.set_block(OAK_PLANKS, x, ground_level + 1, z, None, None); } } } diff --git a/src/element_processing/water_areas.rs b/src/element_processing/water_areas.rs index 781799a..bac8a36 100644 --- a/src/element_processing/water_areas.rs +++ b/src/element_processing/water_areas.rs @@ -164,10 +164,8 @@ fn inverse_floodfill( .collect(); inverse_floodfill_recursive( - min_x, - max_x, - min_z, - max_z, + (min_x, min_z), + (max_x, max_z), ground_level, &outers, &inners, @@ -176,10 +174,8 @@ fn inverse_floodfill( } fn inverse_floodfill_recursive( - min_x: i32, - max_x: i32, - min_z: i32, - max_z: i32, + min: (i32, i32), + max: (i32, i32), ground_level: i32, outers: &[Polygon], inners: &[Polygon], @@ -187,32 +183,23 @@ fn inverse_floodfill_recursive( ) { const ITERATIVE_THRES: i32 = 10_000; - if min_x > max_x || min_z > max_z { + if min.0 > max.0 || min.1 > max.1 { return; } - if (max_x - min_x) * (max_z - min_z) < ITERATIVE_THRES { - inverse_floodfill_iterative( - min_x, - max_x, - min_z, - max_z, - ground_level, - outers, - inners, - editor, - ); + if (max.0 - min.0) * (max.1 - min.1) < ITERATIVE_THRES { + inverse_floodfill_iterative(min, max, ground_level, outers, inners, editor); return; } - let center_x = (min_x + max_x) / 2; - let center_z = (min_z + max_z) / 2; + let center_x = (min.0 + max.0) / 2; + let center_z = (min.1 + max.1) / 2; let quadrants = [ - (min_x, center_x, min_z, center_z), - (center_x, max_x, min_z, center_z), - (min_x, center_x, center_z, max_z), - (center_x, max_x, center_z, max_z), + (min.0, center_x, min.1, center_z), + (center_x, max.0, min.1, center_z), + (min.0, center_x, center_z, max.1), + (center_x, max.0, center_z, max.1), ]; for (min_x, max_x, min_z, max_z) in quadrants { @@ -236,26 +223,24 @@ fn inverse_floodfill_recursive( // This saves on processing time let outers_intersects: Vec<_> = outers .iter() - .cloned() .filter(|poly| poly.intersects(&rect)) + .cloned() .collect(); // Moving this inside the below `if` statement makes it slower for some reason. // I assume it changes how the compiler is able to optimize it let inners_intersects: Vec<_> = inners .iter() - .cloned() .filter(|poly| poly.intersects(&rect)) + .cloned() .collect(); if !outers_intersects.is_empty() { // recurse inverse_floodfill_recursive( - min_x, - max_x, - min_z, - max_z, + (min_x, min_z), + (max_x, max_z), ground_level, &outers_intersects, &inners_intersects, @@ -267,17 +252,15 @@ fn inverse_floodfill_recursive( // once we "zoom in" enough, it's more efficient to switch to iteration fn inverse_floodfill_iterative( - min_x: i32, - max_x: i32, - min_z: i32, - max_z: i32, + min: (i32, i32), + max: (i32, i32), ground_level: i32, outers: &[Polygon], inners: &[Polygon], editor: &mut WorldEditor, ) { - for x in min_x..max_x { - for z in min_z..max_z { + for x in min.0..max.0 { + for z in min.1..max.1 { let p = Point::new(x as f64, z as f64); if outers.iter().any(|poly| poly.contains(&p)) diff --git a/src/osm_parser.rs b/src/osm_parser.rs index 1c6cea1..6e9b146 100644 --- a/src/osm_parser.rs +++ b/src/osm_parser.rs @@ -295,7 +295,7 @@ fn geo_distance(lat1: f64, lat2: f64, lon1: f64, lon2: f64) -> (f64, f64) { // Haversine but optimized for a latitude delta of 0 // returns meters fn lon_distance(lat: f64, lon1: f64, lon2: f64) -> f64 { - const R: f64 = 6371_000.0; + const R: f64 = 6_371_000.0; let d_lon = (lon2 - lon1).to_radians(); let a = lat.to_radians().cos() * lat.to_radians().cos() * (d_lon / 2.0).sin() * (d_lon / 2.0).sin(); @@ -307,7 +307,7 @@ fn lon_distance(lat: f64, lon1: f64, lon2: f64) -> f64 { // Haversine but optimized for a longitude delta of 0 // returns meters fn lat_distance(lat1: f64, lat2: f64) -> f64 { - const R: f64 = 6371_000.0; + const R: f64 = 6_371_000.0; let d_lat = (lat2 - lat1).to_radians(); let a = (d_lat / 2.0).sin() * (d_lat / 2.0).sin(); let c = 2.0 * a.sqrt().atan2((1.0 - a).sqrt());