From 1a6874bfa92b5ad4ccf257ffeb497b0b41fc00ab Mon Sep 17 00:00:00 2001 From: Nils van Lueck Date: Sun, 30 Aug 2026 21:38:36 +0200 Subject: [PATCH] style: apply rustfmt to recent feature code --- crates/content/src/lib.rs | 2 +- crates/content/src/roads.rs | 15 +-- crates/route-editor/src/roads.rs | 39 +++++-- crates/route-editor/src/tools.rs | 5 +- crates/route-editor/src/ui.rs | 8 +- crates/world-render/src/lib.rs | 2 +- crates/world-render/src/plants.rs | 180 +++++++++++++++++++++--------- 7 files changed, 173 insertions(+), 78 deletions(-) diff --git a/crates/content/src/lib.rs b/crates/content/src/lib.rs index e0041d20..45a3805e 100644 --- a/crates/content/src/lib.rs +++ b/crates/content/src/lib.rs @@ -24,8 +24,8 @@ pub use people::{ Crowd, PersonInstance, Pose, StrollAgent, StrollPose, Walkway, WalkwayKind, WalkwayNode, embedded_walkways, stroll_pose, }; -pub use route::{CompiledLine, FieldSource, LineSource, TreeSource}; pub use roads::{RoadPatch, Roads}; +pub use route::{CompiledLine, FieldSource, LineSource, TreeSource}; pub use scenarios::{musterbahn_day, re_4711, to_musterstadt}; pub use terrain::{ Scenery, SceneryInstance, TerrainBuilder, TerrainEdits, TerrainOptions, TerrainStats, diff --git a/crates/content/src/roads.rs b/crates/content/src/roads.rs index 12d784b5..f70ecbb0 100644 --- a/crates/content/src/roads.rs +++ b/crates/content/src/roads.rs @@ -710,11 +710,7 @@ mod tests { #[test] fn a_road_lands_on_the_tiles_it_covers() { // 3 km across, so it spans several 512 m tiles. - let roads = Roads::from_parts( - &[source(440_000.0, 5_715_000.0, 3_000.0, 6.0)], - 32, - 512.0, - ); + let roads = Roads::from_parts(&[source(440_000.0, 5_715_000.0, 3_000.0, 6.0)], 32, 512.0); assert_eq!(roads.len(), 1); assert!(roads.touches((859, 11162)), "{:?}", roads.by_tile.keys()); assert!(!roads.touches((0, 0))); @@ -813,12 +809,9 @@ mod tests { assert_eq!(here.len(), 1); assert_eq!(next.len(), 1); let v = |patch: &RoadPatch| { - patch - .uvs - .iter() - .fold((f32::MAX, f32::MIN), |(lo, hi), uv| { - (lo.min(uv[1]), hi.max(uv[1])) - }) + patch.uvs.iter().fold((f32::MAX, f32::MIN), |(lo, hi), uv| { + (lo.min(uv[1]), hi.max(uv[1])) + }) }; let (lo_here, hi_here) = v(&here[0]); let (lo_next, hi_next) = v(&next[0]); diff --git a/crates/route-editor/src/roads.rs b/crates/route-editor/src/roads.rs index 36fccf01..a70321c5 100644 --- a/crates/route-editor/src/roads.rs +++ b/crates/route-editor/src/roads.rs @@ -284,7 +284,10 @@ fn settings(ui: &mut egui::Ui, dialog: &mut RoadImport, line: &Line) -> bool { .clone() .on_disabled_hover_text(t!("field-import-no-envelope")); } - if start_button.clicked() && ready && let Some(bbox) = envelope_bbox(line) { + if start_button.clicked() + && ready + && let Some(bbox) = envelope_bbox(line) + { start(dialog, bbox); } if ui.button(t!("action-cancel")).clicked() { @@ -335,7 +338,8 @@ fn finished( let mut counts: std::collections::BTreeMap<&str, usize> = std::collections::BTreeMap::new(); for road in roads { - if let Some(class) = road.tags.first().and_then(|t| t.strip_prefix("highway-")) + if let Some(class) = + road.tags.first().and_then(|t| t.strip_prefix("highway-")) { *counts.entry(class).or_insert(0) += 1; } @@ -402,7 +406,8 @@ pub fn pick_at(line: &Line, lat: f64, lon: f64) -> Option { .points .iter() .map(|p| { - let (e, n) = world_coords::geo::to_utm(p.lat.to_radians(), p.lon.to_radians(), zone); + let (e, n) = + world_coords::geo::to_utm(p.lat.to_radians(), p.lon.to_radians(), zone); glam::DVec2::new(e, n) }) .collect(); @@ -767,7 +772,9 @@ mod tests { road_width: Some(4.0), ..Default::default() }; - state.walk_points.push(world_coords::geo::to_ecef_deg(52.0, 10.0, 0.0)); + state + .walk_points + .push(world_coords::geo::to_ecef_deg(52.0, 10.0, 0.0)); assert!( finish(&mut line, &mut state).is_some(), "one point is no road" @@ -798,10 +805,28 @@ mod tests { assert!(allowed(&plain, "primary")); assert!(!allowed(&plain, "track"), "field tracks are opt-in"); assert!(!allowed(&plain, "living_street")); - assert!(allowed(&RoadOptions { tracks: true, ..plain }, "track")); - assert!(allowed(&RoadOptions { tracks: true, ..plain }, "service")); + assert!(allowed( + &RoadOptions { + tracks: true, + ..plain + }, + "track" + )); + assert!(allowed( + &RoadOptions { + tracks: true, + ..plain + }, + "service" + )); assert!( - allowed(&RoadOptions { narrow: true, ..plain }, "living_street"), + allowed( + &RoadOptions { + narrow: true, + ..plain + }, + "living_street" + ), "access ways are the narrow option's own" ); } diff --git a/crates/route-editor/src/tools.rs b/crates/route-editor/src/tools.rs index 21a63217..197ff1a3 100644 --- a/crates/route-editor/src/tools.rs +++ b/crates/route-editor/src/tools.rs @@ -4096,10 +4096,7 @@ pub fn draw_gizmos( gizmos.linestrip( points.iter().map(|p| { origin.0.to_render(*p) - + origin - .0 - .dir_to_render(EnuFrame::at(*p).up) - * MARK_LIFT + + origin.0.dir_to_render(EnuFrame::at(*p).up) * MARK_LIFT }), accent, ); diff --git a/crates/route-editor/src/ui.rs b/crates/route-editor/src/ui.rs index 9c96b77d..2789e360 100644 --- a/crates/route-editor/src/ui.rs +++ b/crates/route-editor/src/ui.rs @@ -4225,7 +4225,13 @@ fn issue_target( .roads .get(*road as usize) .and_then(|road| road.points.first()) - .map(|p| world_coords::geo::to_ecef_deg(p.lat, p.lon, crate::envelope::height(line, focus))), + .map(|p| { + world_coords::geo::to_ecef_deg( + p.lat, + p.lon, + crate::envelope::height(line, focus), + ) + }), Selection::Road(*road as usize), ), } diff --git a/crates/world-render/src/lib.rs b/crates/world-render/src/lib.rs index c99d5a06..17eb03e1 100644 --- a/crates/world-render/src/lib.rs +++ b/crates/world-render/src/lib.rs @@ -42,13 +42,13 @@ pub mod windscreen; pub use farmland::{ CropExt, CropParams, FieldDraw, FieldMaterial, FieldMaterials, FieldSurface, spawn_fields, }; -pub use plants::{FieldPlants, PlantMaterials, update_field_plants}; pub use people::{ CYCLE_PACE, CYCLE_RATE, CharacterAssets, CharacterGraphs, Dressed, GAIT_FADE, Gait, PASSENGER_CULL, PERSON_CULL, Passengers, PeopleClock, Person, Stroller, WALKING_ABOVE, WalkwayHost, WalkwaysBound, bind_walkways, gait, move_strollers, person_bundle, play_gait, spawn_seated, spawn_strollers, }; +pub use plants::{FieldPlants, PlantMaterials, update_field_plants}; pub use roads::{RoadDraw, RoadMaterial, RoadMaterials, RoadSurfaceMark, spawn_roads}; pub use scatter::{ OBJECT_CULL, PendingTrees, Scattered, SceneryIndex, TREE_CULL, TreeModels, Wood, WorldCatalog, diff --git a/crates/world-render/src/plants.rs b/crates/world-render/src/plants.rs index 0927e0a2..f112887c 100644 --- a/crates/world-render/src/plants.rs +++ b/crates/world-render/src/plants.rs @@ -45,15 +45,15 @@ use bevy::gltf::{Gltf, GltfMesh}; use bevy::light::NotShadowCaster; use bevy::prelude::*; use bevy::render::mesh::{Indices, PrimitiveTopology, VertexAttributeValues}; +use fields::CropClass; use fields::phenology::{self, Stage}; use fields::stats::vary; -use fields::CropClass; use crate::{ - farmland::{linear, FieldSurface}, + Season, TextureMips, + farmland::{FieldSurface, linear}, sky::Sky, weather::{WeatherExt, WeatherMaterial}, - Season, TextureMips, }; /// Where two crossed cards hand over to one [m]. A metre of crop at ninety @@ -470,7 +470,10 @@ fn grow( .try_attribute(Mesh::ATTRIBUTE_POSITION) .ok()? .as_float3()?; - let normals = mesh.try_attribute(Mesh::ATTRIBUTE_NORMAL).ok()?.as_float3()?; + let normals = mesh + .try_attribute(Mesh::ATTRIBUTE_NORMAL) + .ok()? + .as_float3()?; let colors = match mesh.try_attribute(Mesh::ATTRIBUTE_COLOR).ok()? { VertexAttributeValues::Float32x4(colors) => colors, _ => return None, @@ -511,13 +514,14 @@ fn grow( // cost allows. let hero_share = match model { Some(model) => { - let by_count = (MAX_HEROES.min(MIN_HEROES.max( - HERO_TRIANGLE_BUDGET / model.tris().max(1), - )) as f64) - .max(1.0); + let by_count = + (MAX_HEROES.min(MIN_HEROES.max(HERO_TRIANGLE_BUDGET / model.tris().max(1))) as f64) + .max(1.0); let (_, wanted) = model_of(crop)?; let cards = area * density as f64; - ((wanted as f64 / density as f64).min(by_count / cards).min(1.0)) as f32 + ((wanted as f64 / density as f64) + .min(by_count / cards) + .min(1.0)) as f32 } None => 0.0, }; @@ -526,11 +530,7 @@ fn grow( let mut cards: Vec = Vec::with_capacity(MAX_CARDS); let mut week_sum = 0.0f64; for (i, tri) in tris.iter().enumerate() { - let (ia, ib, ic) = ( - tri[0] as usize, - tri[1] as usize, - tri[2] as usize, - ); + let (ia, ib, ic) = (tri[0] as usize, tri[1] as usize, tri[2] as usize); let (a, b, c) = ( Vec3::from(positions[ia]), Vec3::from(positions[ib]), @@ -583,13 +583,17 @@ fn grow( } cards.push(Card { pos, - up: if up.length_squared() > 0.5 { up } else { Vec3::Y }, + up: if up.length_squared() > 0.5 { + up + } else { + Vec3::Y + }, yaw: (vary(i as u64 * 3 + k * 13, 0x91A7 + 7) as f32 - 0.5) * 1.1, width: card_width(crop) * (0.75 + 0.5 * vary(i as u64 + k, 0x91A7 + 6) as f32), height: (growth.height * (0.7 + 0.5 * vary(i as u64 + k * 11, 0x91A7 + 9) as f32) * scale) - .max(0.03), + .max(0.03), lean: (vary(i as u64 + k * 7, 0x91A7 + 10) as f32 - 0.5) * 0.35, tint, light: vary(i as u64 + k * 13, 0x91A7 + 21) as f32, @@ -657,8 +661,7 @@ impl PlantMaterials { self.day = Some(today); for (crop, handle) in &self.by_crop { if let Some(mut material) = assets.get_mut(handle) { - material.base.base_color = - stand_colour(phenology::growth(*crop, month, day, 0)); + material.base.base_color = stand_colour(phenology::growth(*crop, month, day, 0)); } } true @@ -754,7 +757,13 @@ pub fn update_field_plants( mut plants: ResMut, mut models: ResMut, sky: Res, - mut fields: Query<(Entity, &FieldSurface, &Mesh3d, &GlobalTransform, &mut FieldPlants)>, + mut fields: Query<( + Entity, + &FieldSurface, + &Mesh3d, + &GlobalTransform, + &mut FieldPlants, + )>, cameras: Query<(&Camera, &GlobalTransform)>, ) { let Some((_, at)) = cameras.iter().find(|(camera, _)| camera.is_active) else { @@ -798,7 +807,13 @@ pub fn update_field_plants( // Grown for the day already? The day's colour rode in with the // material; only stage, height, winter and a landed model rebuild. - let key = CropKey::of(surface.crop, sky.month, sky.day, state.week, model.is_some()); + let key = CropKey::of( + surface.crop, + sky.month, + sky.day, + state.week, + model.is_some(), + ); if state.grown == Some(key) || builds >= BUILD_BUDGET { continue; } @@ -808,8 +823,13 @@ pub fn update_field_plants( continue; }; state.grown = Some(key); - let Some(grown) = grow(surface_mesh, surface.crop, sky.month, sky.day, model.as_deref()) - else { + let Some(grown) = grow( + surface_mesh, + surface.crop, + sky.month, + sky.day, + model.as_deref(), + ) else { continue; }; state.week = grown.week; @@ -837,7 +857,12 @@ pub fn update_field_plants( ( at, hero_mesh(part, &grown.cards, stand), - models.dressed(&part.material, &standards, &mut materials, part.uvs.is_some()), + models.dressed( + &part.material, + &standards, + &mut materials, + part.uvs.is_some(), + ), ) }) .collect::>() @@ -850,31 +875,46 @@ pub fn update_field_plants( continue; }; let handle = meshes.add(hero_mesh.clone()); - spawned.push((parent.spawn(( - Mesh3d(handle.clone()), + spawned.push(( + parent + .spawn(( + Mesh3d(handle.clone()), + MeshMaterial3d(material.clone()), + Transform::IDENTITY, + range(0.0, LOD0_END), + NotShadowCaster, + )) + .id(), + handle.id(), + )); + } + } + let filler = meshes.add(card_mesh(&grown.cards, false)); + spawned.push(( + parent + .spawn(( + Mesh3d(filler.clone()), MeshMaterial3d(material.clone()), Transform::IDENTITY, range(0.0, LOD0_END), NotShadowCaster, - )).id(), handle.id())); - } - } - let filler = meshes.add(card_mesh(&grown.cards, false)); - spawned.push((parent.spawn(( - Mesh3d(filler.clone()), - MeshMaterial3d(material.clone()), - Transform::IDENTITY, - range(0.0, LOD0_END), - NotShadowCaster, - )).id(), filler.id())); + )) + .id(), + filler.id(), + )); let sparse = meshes.add(card_mesh(&grown.cards, true)); - spawned.push((parent.spawn(( - Mesh3d(sparse.clone()), - MeshMaterial3d(material), - Transform::IDENTITY, - range(LOD0_END, PLANT_CULL), - NotShadowCaster, - )).id(), sparse.id())); + spawned.push(( + parent + .spawn(( + Mesh3d(sparse.clone()), + MeshMaterial3d(material), + Transform::IDENTITY, + range(LOD0_END, PLANT_CULL), + NotShadowCaster, + )) + .id(), + sparse.id(), + )); }); state.lods.extend(spawned); } @@ -945,7 +985,10 @@ fn card_mesh(cards: &[Card], sparse: bool) -> Mesh { } } - let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default()); + let mut mesh = Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::default(), + ); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions); mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals); mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors); @@ -1011,7 +1054,10 @@ fn hero_mesh(part: &PlantPart, cards: &[Card], stand: [f32; 3]) -> Mesh { } } - let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default()); + let mut mesh = Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::default(), + ); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions); mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals); mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors); @@ -1079,11 +1125,13 @@ mod tests { mesh.indices().map(Indices::len).unwrap_or(0) } - /// One square of ground, `size` metres on a side, as a patch's mesh — /// two triangles, flat, with the vertex colours a field piece carries. fn patch(size: f32) -> Mesh { - let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default()); + let mut mesh = Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::default(), + ); mesh.insert_attribute( Mesh::ATTRIBUTE_POSITION, vec![ @@ -1133,10 +1181,23 @@ mod tests { // third of the cards, one quad of the cross each. let kept = grown.cards.iter().filter(|c| c.sparse).count(); assert_eq!(index_count(&far) / 6, kept, "one quad per kept card"); - assert_eq!(index_count(&near) / 12, grown.cards.len(), "two quads a card"); + assert_eq!( + index_count(&near) / 12, + grown.cards.len(), + "two quads a card" + ); // And the thinning is the draw's, not a hash quirk: about a third. - assert!(kept * 3 < grown.cards.len() * 2, "{kept} of {}", grown.cards.len()); - assert!(kept * 3 > grown.cards.len(), "{} of {}", kept, grown.cards.len()); + assert!( + kept * 3 < grown.cards.len() * 2, + "{kept} of {}", + grown.cards.len() + ); + assert!( + kept * 3 > grown.cards.len(), + "{} of {}", + kept, + grown.cards.len() + ); } #[test] @@ -1207,11 +1268,24 @@ mod tests { _ => panic!("colours are float quads"), }; assert!(colors[0][1] < 0.4 * 0.8 + 1e-6, "foot darker than head"); - assert!((colors[1][1] - 0.4 * 1.05).abs() < 0.2, "head near the stand colour"); + assert!( + (colors[1][1] - 0.4 * 1.05).abs() < 0.2, + "head near the stand colour" + ); // Not a hero: nothing is baked. - let plain = Card { hero: false, ..card }; + let plain = Card { + hero: false, + ..card + }; let empty = hero_mesh(&model.parts[0], &[plain], [0.2, 0.4, 0.1]); - assert!(empty.attribute(Mesh::ATTRIBUTE_POSITION).unwrap().as_float3().unwrap().is_empty()); + assert!( + empty + .attribute(Mesh::ATTRIBUTE_POSITION) + .unwrap() + .as_float3() + .unwrap() + .is_empty() + ); } #[test]