style(simulation): cargo fmt on the step-canvas batch

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 03:15:58 +02:00
co-authored by Claude Fable 5
parent 51f927de5d
commit ab52897d66
4 changed files with 87 additions and 28 deletions
+10 -5
View File
@@ -383,7 +383,11 @@ impl GenWorkItem {
/// update to the same one. `None` for every other variant.
pub fn step_canvas_supersede_key(
&self,
) -> Option<(ConnectionId, &str, crate::atlas::step_canvas::StepCanvasRung)> {
) -> Option<(
ConnectionId,
&str,
crate::atlas::step_canvas::StepCanvasRung,
)> {
if let GenWorkItem::DeriveStepCanvas {
body_id,
conn_id,
@@ -1185,10 +1189,11 @@ fn run_work_item(
// ~45 ms run_layer1 re-derive, never pay it twice.
// body_params threads the real moisture ceiling into the
// T-1184 hydrology solve (merge seam resolution).
let (l1, ta) = terrain_cache
.lock()
.unwrap()
.get_or_derive(body_id, &working, Some(body_params.as_ref()));
let (l1, ta) = terrain_cache.lock().unwrap().get_or_derive(
body_id,
&working,
Some(body_params.as_ref()),
);
let climate = ClimateConstants::default();
let raw = crate::atlas::step_canvas::build_step_canvas(
*body_seed,
+5 -3
View File
@@ -563,9 +563,11 @@ fn drain_generation_completions(
global_tier_cache.as_mut().insert(body_id, *canvas);
} else {
let tick = time.as_ref().map(|t| t.tick).unwrap_or(0);
step_canvas_cache
.as_mut()
.insert((body_id, rung, center, extent, min_wl_m), *canvas, tick);
step_canvas_cache.as_mut().insert(
(body_id, rung, center, extent, min_wl_m),
*canvas,
tick,
);
}
}
}
+50 -11
View File
@@ -550,8 +550,13 @@ fn settlement_ids_for_canvas(
let anchors: Vec<(f64, f64, u32)> = placements
.iter()
.map(|p| {
let (wx, wy) =
pixel_to_world_m(p.position.0 as f64, p.position.1 as f64, ta.w, ta.h, body_radius_km);
let (wx, wy) = pixel_to_world_m(
p.position.0 as f64,
p.position.1 as f64,
ta.w,
ta.h,
body_radius_km,
);
(wx, wy, p.city_id as u32)
})
.collect();
@@ -679,7 +684,10 @@ fn invent_courses_for_canvas(
/// byte-identical acceptance gate below is what keeps the two paths honest
/// against silent drift, same as any other intentionally-parallel
/// implementation in this codebase).
fn crop_course_for_canvas(course: &InventedCourse, canvas_rect: (f64, f64, f64, f64)) -> Option<RiverCourse> {
fn crop_course_for_canvas(
course: &InventedCourse,
canvas_rect: (f64, f64, f64, f64),
) -> Option<RiverCourse> {
let (x0, y0, x1, y1) = canvas_rect;
let inside = |p: &(f64, f64)| p.0 >= x0 && p.0 <= x1 && p.1 >= y0 && p.1 <= y1;
@@ -741,7 +749,11 @@ fn crop_course_for_canvas(course: &InventedCourse, canvas_rect: (f64, f64, f64,
/// request's own `extent` field directly (D-255(a): "the fixed 3840×2160 px
/// budget... at 1 gridunit-per-screen-px" — cell count = canvas px count at
/// every fixed rung, Dudley round-2 §(c)).
fn resolve_canvas_extent(rung: StepCanvasRung, extent: (u32, u32), body_radius_km: f64) -> (u32, u32) {
fn resolve_canvas_extent(
rung: StepCanvasRung,
extent: (u32, u32),
body_radius_km: f64,
) -> (u32, u32) {
match rung.global_cell_counts(body_radius_km) {
Some((cols, rows)) => (cols, rows),
None => (extent.0.max(1), extent.1.max(1)),
@@ -820,7 +832,14 @@ pub fn build_step_canvas(
(center.0 as f64, center.1 as f64)
};
let canvas_rect = fixed_canvas_world_rect(center_world_m, half_w, half_h, width as i32, height as i32, step_m);
let canvas_rect = fixed_canvas_world_rect(
center_world_m,
half_w,
half_h,
width as i32,
height as i32,
step_m,
);
let invented_courses = if rung.is_global() {
Vec::new()
} else {
@@ -1398,7 +1417,13 @@ pub fn serve_step_canvas_request(
};
}
} else {
let key: StepCanvasKey = (req.body_id.clone(), req.rung, req.center, req.extent, min_wl_m);
let key: StepCanvasKey = (
req.body_id.clone(),
req.rung,
req.center,
req.extent,
min_wl_m,
);
if let Some(canvas) = canvas_cache.get(&key, current_tick, body_class) {
return StepCanvasResponse {
body_id: req.body_id.clone(),
@@ -1415,7 +1440,8 @@ pub fn serve_step_canvas_request(
// inline, D-255(d)).
let heightmap_path = match resolver.resolve(&req.body_id) {
Ok(p) => p,
Err(SourceResolveError::UnknownBody(_)) | Err(SourceResolveError::NoTerrainReference { .. }) => {
Err(SourceResolveError::UnknownBody(_))
| Err(SourceResolveError::NoTerrainReference { .. }) => {
return StepCanvasResponse {
body_id: req.body_id.clone(),
rung: req.rung,
@@ -1603,7 +1629,13 @@ mod tests {
#[test]
fn storage_axis_evicts_after_ttl_regardless_of_sim_state_freshness() {
let mut cache = StepCanvasCache::new(8);
let key: StepCanvasKey = ("BodyA".to_string(), StepCanvasRung::Chunk, (0, 0), (4, 4), 0);
let key: StepCanvasKey = (
"BodyA".to_string(),
StepCanvasRung::Chunk,
(0, 0),
(4, 4),
0,
);
cache.insert(key.clone(), dummy_canvas(), 0);
let ttl = storage_ttl_ticks(StepCanvasRung::Chunk);
@@ -1663,7 +1695,9 @@ mod tests {
0,
);
cache.insert(key.clone(), dummy_canvas(), 0);
assert!(cache.get(&key, 1, BodyDrivingClockClass::Moonless).is_some());
assert!(cache
.get(&key, 1, BodyDrivingClockClass::Moonless)
.is_some());
assert_eq!(cache.len(), 1, "a fresh hit must not evict the entry");
}
@@ -1813,8 +1847,13 @@ mod tests {
// case (two attractors resolving to the same pixel).
let a = test_placement(9, ((ta.h / 2) as u16, (ta.w / 2) as u16));
let b = test_placement(3, ((ta.h / 2) as u16, (ta.w / 2) as u16));
let (anchor_wx, anchor_wy) =
pixel_to_world_m(a.position.0 as f64, a.position.1 as f64, ta.w, ta.h, body_radius_km);
let (anchor_wx, anchor_wy) = pixel_to_world_m(
a.position.0 as f64,
a.position.1 as f64,
ta.w,
ta.h,
body_radius_km,
);
let ids = settlement_ids_for_canvas(
&[a, b],
+22 -9
View File
@@ -302,18 +302,22 @@ fn step_canvas_cache_round_trip_matches_fresh_derive_every_fixed_rung() {
let rn = fixture_river_network(&hm);
let params = fixture_params();
let fresh_raw = build_step_canvas(
seed, "gate-body", &params, &ta, &rn, &[], rung, center, extent, &climate, min_wl_m,
seed,
"gate-body",
&params,
&ta,
&rn,
&[],
rung,
center,
extent,
&climate,
min_wl_m,
);
let fresh_encoded = encode_step_canvas(&fresh_raw);
let mut cache = StepCanvasCache::new(8);
let key = (
"gate-body".to_string(),
rung,
center,
extent,
min_wl_m,
);
let key = ("gate-body".to_string(), rung, center, extent, min_wl_m);
assert!(cache.get(&key, 0, body_class).is_none());
cache.insert(key.clone(), fresh_encoded.clone(), 0);
@@ -331,7 +335,16 @@ fn step_canvas_cache_round_trip_matches_fresh_derive_every_fixed_rung() {
let rn2 = fixture_river_network(&hm2);
let params2 = fixture_params();
let recomputed_raw = build_step_canvas(
seed, "gate-body", &params2, &ta2, &rn2, &[], rung, center, extent, &climate,
seed,
"gate-body",
&params2,
&ta2,
&rn2,
&[],
rung,
center,
extent,
&climate,
min_wl_m,
);
let recomputed_encoded = encode_step_canvas(&recomputed_raw);