feat(simulation): cache TerrainAnalysis + derive basin_direction from the D8 thalweg (T-1044, T-1047)
T-1044: run_layer1 now returns TerrainAnalysis (carried transiently on CascadeSnapshot, dropped after the district + road-graph passes), eliminating the redundant per-body drainage::analyze + TerrainAnalysis::analyze re-run flagged by PERF/TODO(T-1044). Not persisted on the LRU-cached state (D-203/T-1048 size concern). T-1047: basin_direction is now derived from the real D8 thalweg. run_layer1 aggregates a per-district dominant D8 direction from the live fdir grid (carried transiently on DrainageResult), threaded via Layer1Output.district_basin_dirs -> derive_all_districts -> DistrictProfile.basin_direction; derive_chunk_context reads it directly. Removed the false derive_basin_direction (it branched on ocean_fraction_q then read seed bits despite a doc comment claiming an elev_q/slope_q D8 proxy) + corrected the module contract. D-239 §8 (D8 thalweg) now actually honoured. 1559 tests pass; golden byte-identical (district_basin_dirs is #[serde(skip)], transient). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -145,6 +145,13 @@ pub fn handle_atlas_request(
|
||||
// working grid all Layer-1 positions are expressed in (#960).
|
||||
grid_w: state.heightmap_width,
|
||||
grid_h: state.heightmap_height,
|
||||
// district_basin_dirs is transient — it is aggregated during run_layer1
|
||||
// and consumed by derive_all_districts before being stored on
|
||||
// BodyWorldState. When reconstructing Layer1Output from the cache for
|
||||
// the client response, the per-district direction is already encoded in
|
||||
// DistrictProfile.basin_direction (BodyWorldState.districts) and is not
|
||||
// needed again here. Supply an empty map.
|
||||
district_basin_dirs: std::collections::BTreeMap::new(),
|
||||
};
|
||||
let district_grid = build_district_grid(state);
|
||||
return AtlasLayerResponse {
|
||||
@@ -271,6 +278,7 @@ mod tests {
|
||||
temperature_c: Some(10.0),
|
||||
moisture_q: 50,
|
||||
vegetation_class: VegetationClass::Barren,
|
||||
basin_direction: crate::atlas::scale::BasinDirection::default(),
|
||||
};
|
||||
let mut state = BodyWorldState {
|
||||
body_id: "GJ1c".into(),
|
||||
|
||||
Reference in New Issue
Block a user