Skip to content

Commit

Permalink
fix remaining clippys
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen D committed Oct 27, 2024
1 parent 4b9f9f7 commit 31fe15b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/data_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/element_processing/tourisms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
59 changes: 21 additions & 38 deletions src/element_processing/water_areas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -176,43 +174,32 @@ 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],
editor: &mut WorldEditor,
) {
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 {
Expand All @@ -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,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/osm_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down

0 comments on commit 31fe15b

Please sign in to comment.