Skip to content

Commit f1c4cfe

Browse files
committed
migrate to rust edition 2024
1 parent 99fbb6b commit f1c4cfe

36 files changed

+1917
-1730
lines changed

Cargo.lock

Lines changed: 1369 additions & 1154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "arnis"
33
version = "2.4.0"
4-
edition = "2021"
4+
edition = "2024"
55
description = "Arnis - Generate real life cities in Minecraft"
66
homepage = "https://github.com/louis-e/arnis"
77
repository = "https://github.com/louis-e/arnis"
@@ -101,23 +101,3 @@ suspicious = "warn"
101101
style = "warn"
102102
complexity = "warn"
103103
perf = "warn"
104-
105-
106-
# Later:
107-
# pedantic = { level = "warn", priority = -1 }
108-
109-
# allow_attributes = "warn"
110-
# allow_attributes_without_reason = "warn"
111-
# Allowed lints (might be reconsidered later)
112-
113-
# cast_possible_truncation = "allow" # This is not useful as we have many intentional casts
114-
# cast_sign_loss = "allow" # This is not useful as we have many intentional casts
115-
# inline_always = "allow" # https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#inline_always
116-
# too_many_lines = "allow" # Many functions are long --> Reformatting would be better
117-
# match_same_arms = "allow" # Sometimes useful for clarity
118-
# module_name_repetitions = "allow" # Sometimes useful for clarity
119-
# unreadable_literal = "allow"
120-
# similar_names = "allow"
121-
# float_cmp = "allow"
122-
# cast_lossless = "allow"
123-
# fn_params_excessive_bools = "allow"

src/bedrock_block_map.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -658,15 +658,15 @@ fn convert_slab(
658658
let mut states = HashMap::new();
659659

660660
// Convert type: Java uses "top/bottom/double", Bedrock uses "top_slot_bit"
661-
if let Some(props) = props {
662-
if let Some(fastnbt::Value::String(slab_type)) = props.get("type") {
663-
let top_slot = slab_type == "top";
664-
states.insert(
665-
"top_slot_bit".to_string(),
666-
BedrockBlockStateValue::Bool(top_slot),
667-
);
668-
// Note: "double" slabs in Java become full blocks in Bedrock (different block ID)
669-
}
661+
if let Some(props) = props
662+
&& let Some(fastnbt::Value::String(slab_type)) = props.get("type")
663+
{
664+
let top_slot = slab_type == "top";
665+
states.insert(
666+
"top_slot_bit".to_string(),
667+
BedrockBlockStateValue::Bool(top_slot),
668+
);
669+
// Note: "double" slabs in Java become full blocks in Bedrock (different block ID)
670670
}
671671

672672
// Default to bottom if not specified
@@ -727,13 +727,13 @@ fn convert_log(
727727
let mut states = HashMap::new();
728728

729729
// Convert axis: Java uses "x/y/z", Bedrock uses "pillar_axis"
730-
if let Some(props) = props {
731-
if let Some(fastnbt::Value::String(axis)) = props.get("axis") {
732-
states.insert(
733-
"pillar_axis".to_string(),
734-
BedrockBlockStateValue::String(axis.clone()),
735-
);
736-
}
730+
if let Some(props) = props
731+
&& let Some(fastnbt::Value::String(axis)) = props.get("axis")
732+
{
733+
states.insert(
734+
"pillar_axis".to_string(),
735+
BedrockBlockStateValue::String(axis.clone()),
736+
);
737737
}
738738

739739
// Default to y-axis if not specified

src/clipping.rs

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ fn clip_polyline_to_bbox(nodes: &[ProcessedNode], xzbbox: &XZBBox) -> Vec<Proces
259259
// Preserve endpoint IDs where possible
260260
if result.len() >= 2 {
261261
let tolerance = 50.0;
262-
if let Some(first_orig) = nodes.first() {
263-
if matches_endpoint(
262+
if let Some(first_orig) = nodes.first()
263+
&& matches_endpoint(
264264
(f64::from(result[0].x), f64::from(result[0].z)),
265265
first_orig,
266266
tolerance,
267-
) {
268-
result[0].id = first_orig.id;
269-
}
267+
)
268+
{
269+
result[0].id = first_orig.id;
270270
}
271271
if let Some(last_orig) = nodes.last() {
272272
let last_idx = result.len() - 1;
@@ -320,26 +320,12 @@ fn clip_polygon_sutherland_hodgman(
320320
let next_inside = point_inside_edge(next, edge_x1, edge_z1, edge_x2, edge_z2);
321321

322322
if next_inside {
323-
if !current_inside {
324-
if let Some(mut intersection) = line_edge_intersection(
323+
if !current_inside
324+
&& let Some(mut intersection) = line_edge_intersection(
325325
current.0, current.1, next.0, next.1, edge_x1, edge_z1, edge_x2, edge_z2,
326-
) {
327-
// Clamp to current edge only
328-
match edge_idx {
329-
0 => intersection.1 = min_z,
330-
1 => intersection.0 = max_x,
331-
2 => intersection.1 = max_z,
332-
3 => intersection.0 = min_x,
333-
_ => {}
334-
}
335-
clipped.push(intersection);
336-
}
337-
}
338-
clipped.push(next);
339-
} else if current_inside {
340-
if let Some(mut intersection) = line_edge_intersection(
341-
current.0, current.1, next.0, next.1, edge_x1, edge_z1, edge_x2, edge_z2,
342-
) {
326+
)
327+
{
328+
// Clamp to current edge only
343329
match edge_idx {
344330
0 => intersection.1 = min_z,
345331
1 => intersection.0 = max_x,
@@ -349,6 +335,20 @@ fn clip_polygon_sutherland_hodgman(
349335
}
350336
clipped.push(intersection);
351337
}
338+
clipped.push(next);
339+
} else if current_inside
340+
&& let Some(mut intersection) = line_edge_intersection(
341+
current.0, current.1, next.0, next.1, edge_x1, edge_z1, edge_x2, edge_z2,
342+
)
343+
{
344+
match edge_idx {
345+
0 => intersection.1 = min_z,
346+
1 => intersection.0 = max_x,
347+
2 => intersection.1 = max_z,
348+
3 => intersection.0 = min_x,
349+
_ => {}
350+
}
351+
clipped.push(intersection);
352352
}
353353
}
354354

@@ -388,24 +388,24 @@ fn clip_polygon_sutherland_hodgman_simple(
388388
let next_inside = point_inside_edge(next, edge_x1, edge_z1, edge_x2, edge_z2);
389389

390390
if next_inside {
391-
if !current_inside {
392-
if let Some(mut intersection) = line_edge_intersection(
391+
if !current_inside
392+
&& let Some(mut intersection) = line_edge_intersection(
393393
current.0, current.1, next.0, next.1, edge_x1, edge_z1, edge_x2, edge_z2,
394-
) {
395-
intersection.0 = intersection.0.clamp(min_x, max_x);
396-
intersection.1 = intersection.1.clamp(min_z, max_z);
397-
clipped.push(intersection);
398-
}
399-
}
400-
clipped.push(next);
401-
} else if current_inside {
402-
if let Some(mut intersection) = line_edge_intersection(
403-
current.0, current.1, next.0, next.1, edge_x1, edge_z1, edge_x2, edge_z2,
404-
) {
394+
)
395+
{
405396
intersection.0 = intersection.0.clamp(min_x, max_x);
406397
intersection.1 = intersection.1.clamp(min_z, max_z);
407398
clipped.push(intersection);
408399
}
400+
clipped.push(next);
401+
} else if current_inside
402+
&& let Some(mut intersection) = line_edge_intersection(
403+
current.0, current.1, next.0, next.1, edge_x1, edge_z1, edge_x2, edge_z2,
404+
)
405+
{
406+
intersection.0 = intersection.0.clamp(min_x, max_x);
407+
intersection.1 = intersection.1.clamp(min_z, max_z);
408+
clipped.push(intersection);
409409
}
410410
}
411411

@@ -632,10 +632,11 @@ fn remove_consecutive_duplicates(polygon: Vec<(f64, f64)>) -> Vec<(f64, f64)> {
632632
let mut result: Vec<(f64, f64)> = Vec::with_capacity(polygon.len());
633633

634634
for p in &polygon {
635-
if let Some(last) = result.last() {
636-
if (p.0 - last.0).abs() < eps && (p.1 - last.1).abs() < eps {
637-
continue;
638-
}
635+
if let Some(last) = result.last()
636+
&& (p.0 - last.0).abs() < eps
637+
&& (p.1 - last.1).abs() < eps
638+
{
639+
continue;
639640
}
640641
result.push(*p);
641642
}
@@ -682,25 +683,25 @@ fn assign_node_ids_preserving_endpoints(
682683
let is_last = i == last_index;
683684

684685
if is_first || is_last {
685-
if let Some(first) = original_first {
686-
if matches_endpoint(coord, first, tolerance) {
687-
return ProcessedNode {
688-
id: first.id,
689-
x: coord.0.round() as i32,
690-
z: coord.1.round() as i32,
691-
tags: HashMap::new(),
692-
};
693-
}
686+
if let Some(first) = original_first
687+
&& matches_endpoint(coord, first, tolerance)
688+
{
689+
return ProcessedNode {
690+
id: first.id,
691+
x: coord.0.round() as i32,
692+
z: coord.1.round() as i32,
693+
tags: HashMap::new(),
694+
};
694695
}
695-
if let Some(last) = original_last {
696-
if matches_endpoint(coord, last, tolerance) {
697-
return ProcessedNode {
698-
id: last.id,
699-
x: coord.0.round() as i32,
700-
z: coord.1.round() as i32,
701-
tags: HashMap::new(),
702-
};
703-
}
696+
if let Some(last) = original_last
697+
&& matches_endpoint(coord, last, tolerance)
698+
{
699+
return ProcessedNode {
700+
id: last.id,
701+
x: coord.0.round() as i32,
702+
z: coord.1.round() as i32,
703+
tags: HashMap::new(),
704+
};
704705
}
705706
}
706707

src/data_processing.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::map_renderer;
1111
use crate::osm_parser::ProcessedElement;
1212
use crate::progress::{emit_gui_progress_update, emit_map_preview_ready, emit_open_mcworld_file};
1313
#[cfg(feature = "gui")]
14-
use crate::telemetry::{send_log, LogLevel};
14+
use crate::telemetry::{LogLevel, send_log};
1515
use crate::world_editor::{WorldEditor, WorldFormat};
1616
use colored::Colorize;
1717
use indicatif::{ProgressBar, ProgressStyle};
@@ -279,39 +279,39 @@ pub fn generate_world_with_options(
279279

280280
// Update player spawn Y coordinate based on terrain height after generation
281281
#[cfg(feature = "gui")]
282-
if world_format == WorldFormat::JavaAnvil {
283-
if let Some(spawn_coords) = &args.spawn_point {
284-
use crate::gui::update_player_spawn_y_after_generation;
285-
let bbox_string = format!(
286-
"{},{},{},{}",
287-
args.bbox.min().lng(),
288-
args.bbox.min().lat(),
289-
args.bbox.max().lng(),
290-
args.bbox.max().lat()
291-
);
292-
293-
if let Err(e) = update_player_spawn_y_after_generation(
294-
&args.path,
295-
Some(*spawn_coords),
296-
bbox_string,
297-
args.scale,
298-
&ground,
299-
) {
300-
let warning_msg = format!("Failed to update spawn point Y coordinate: {e}");
301-
eprintln!("Warning: {warning_msg}");
302-
#[cfg(feature = "gui")]
303-
send_log(LogLevel::Warning, &warning_msg);
304-
}
282+
if world_format == WorldFormat::JavaAnvil
283+
&& let Some(spawn_coords) = &args.spawn_point
284+
{
285+
use crate::gui::update_player_spawn_y_after_generation;
286+
let bbox_string = format!(
287+
"{},{},{},{}",
288+
args.bbox.min().lng(),
289+
args.bbox.min().lat(),
290+
args.bbox.max().lng(),
291+
args.bbox.max().lat()
292+
);
293+
294+
if let Err(e) = update_player_spawn_y_after_generation(
295+
&args.path,
296+
Some(*spawn_coords),
297+
bbox_string,
298+
args.scale,
299+
&ground,
300+
) {
301+
let warning_msg = format!("Failed to update spawn point Y coordinate: {e}");
302+
eprintln!("Warning: {warning_msg}");
303+
#[cfg(feature = "gui")]
304+
send_log(LogLevel::Warning, &warning_msg);
305305
}
306306
}
307307

308308
emit_gui_progress_update(99.0, "Finalizing world...");
309309

310310
// For Bedrock format, emit event to open the mcworld file
311-
if world_format == WorldFormat::BedrockMcWorld {
312-
if let Some(path_str) = output_path.to_str() {
313-
emit_open_mcworld_file(path_str);
314-
}
311+
if world_format == WorldFormat::BedrockMcWorld
312+
&& let Some(path_str) = output_path.to_str()
313+
{
314+
emit_open_mcworld_file(path_str);
315315
}
316316

317317
// Generate top-down map preview silently in background after completion (Java only)

src/element_processing/amenities.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::args::Args;
22
use crate::block_definitions::{
3-
Block, BLACK_CONCRETE, CAULDRON, COBBLESTONE_WALL, GLOWSTONE, GRAY_CONCRETE, IRON_BLOCK,
3+
BLACK_CONCRETE, Block, CAULDRON, COBBLESTONE_WALL, GLOWSTONE, GRAY_CONCRETE, IRON_BLOCK,
44
LIGHT_GRAY_CONCRETE, OAK_FENCE, OAK_LOG, OAK_PLANKS, SMOOTH_STONE, STONE_BLOCK_SLAB,
55
STONE_BRICK_SLAB, WATER,
66
};
@@ -12,16 +12,16 @@ use crate::world_editor::WorldEditor;
1212

1313
pub fn generate_amenities(editor: &mut WorldEditor<'_>, element: &ProcessedElement, args: &Args) {
1414
// Skip if 'layer' or 'level' is negative in the tags
15-
if let Some(layer) = element.tags().get("layer") {
16-
if layer.parse::<i32>().unwrap_or(0) < 0 {
17-
return;
18-
}
15+
if let Some(layer) = element.tags().get("layer")
16+
&& layer.parse::<i32>().unwrap_or(0) < 0
17+
{
18+
return;
1919
}
2020

21-
if let Some(level) = element.tags().get("level") {
22-
if level.parse::<i32>().unwrap_or(0) < 0 {
23-
return;
24-
}
21+
if let Some(level) = element.tags().get("level")
22+
&& level.parse::<i32>().unwrap_or(0) < 0
23+
{
24+
return;
2525
}
2626

2727
if let Some(amenity_type) = element.tags().get("amenity") {

src/element_processing/barriers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::block_definitions::{
2-
Block, AIR, BRICK, COBBLESTONE_WALL, GLASS, LIGHT_GRAY_CONCRETE, OAK_FENCE, OAK_LEAVES, STONE,
2+
AIR, BRICK, Block, COBBLESTONE_WALL, GLASS, LIGHT_GRAY_CONCRETE, OAK_FENCE, OAK_LEAVES, STONE,
33
STONE_BRICK_SLAB, STONE_BRICK_WALL,
44
};
55
use crate::bresenham::bresenham_line;

0 commit comments

Comments
 (0)