Skip to content

Commit 18417be

Browse files
committed
Clarify doc comments around f32 downcast and bilinear widening
Addresses Copilot review comments on the shrink-grid-precision PR. All changes are docs-only — no behavioural change: - Water-blend grid doc: point to `ground_generation`'s 0.5 classifier as the actual threshold consumer instead of the vague "renderer". - Bilinear-widening comments (both water_blend and heights): previous wording implied widening recovered precision, which it doesn't. The real guarantee is that f32's ~10⁻⁷ precision across the stored Y range is far below the 0.5 half-block window that `round()` uses, so the final i32 Y matches the f64 path except in a vanishingly narrow half-integer boundary band.
1 parent feefde8 commit 18417be

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/ground.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ impl Ground {
175175
// continuous — the renderer's hard `> 0.5` threshold then traces
176176
// a clean curved shoreline contour instead of the raw ESA 10 m
177177
// rectangular grid edge.
178-
// Widen f32 storage to f64 here so the bilinear interpolation
179-
// (and the downstream 0.5-threshold comparison) doesn't lose any
180-
// precision vs the previous all-f64 implementation.
178+
// Widen f32 storage to f64 for the bilinear arithmetic. This
179+
// doesn't recover the ~10⁻⁷ precision lost at storage, but it
180+
// prevents extra rounding from accumulating in the four
181+
// multiply-adds + the threshold comparison downstream.
181182
let w00 = lc.water_blend_grid[z0][x0] as f64;
182183
let w10 = lc.water_blend_grid[z0][x1] as f64;
183184
let w01 = lc.water_blend_grid[z1][x0] as f64;
@@ -300,11 +301,13 @@ impl Ground {
300301
let z1 = (z0 + 1).min(data.height - 1);
301302
let dx = fx - x0 as f64;
302303
let dz = fz - z0 as f64;
303-
// Widen f32 storage to f64 for the bilinear, same as we always did
304-
// before f32 storage — the arithmetic stays in f64 so rounding to the
305-
// nearest block Y matches the old behaviour bit-for-bit on anything
306-
// the previous f64 storage could represent exactly (integer-valued
307-
// elevations do).
304+
// Widen f32 storage to f64 for the bilinear arithmetic. The real
305+
// property we rely on: across the Minecraft Y range (roughly −64 up
306+
// through a few thousand even with --disable-height-limit), f32's
307+
// mantissa gives ~10⁻⁷ precision per stored cell, which is far
308+
// smaller than the 0.5-block half-width used by `round()` below.
309+
// So for any value that isn't pathologically close to a half-integer
310+
// boundary, the final `result.round() as i32` matches the f64 path.
308311
let v00 = data.heights[z0][x0] as f64;
309312
let v10 = data.heights[z0][x1] as f64;
310313
let v01 = data.heights[z1][x0] as f64;

src/land_cover.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ pub struct LandCoverData {
6464
/// 0 = non-water, 1 = shore water, 2+ = progressively deeper water.
6565
pub water_distance: Vec<Vec<u8>>,
6666
/// Pre-smoothed water-ness field in [0, 1] — a Gaussian-blurred version
67-
/// of the binary `grid == LC_WATER` mask. Used by `ground.water_blend()`
68-
/// and compared against a hard 0.5 threshold in the renderer so the
69-
/// shoreline follows the smoothed contour's 0.5 isoline instead of the
70-
/// raw ESA 10 m rectangular grid edge.
67+
/// of the binary `grid == LC_WATER` mask. Sampled via `ground.water_blend()`
68+
/// and compared against a hard 0.5 threshold inside `ground_generation`
69+
/// (water classification path) so the shoreline follows the smoothed
70+
/// contour's 0.5 isoline instead of the raw ESA 10 m rectangular grid
71+
/// edge.
7172
///
7273
/// Stored as `f32` on purpose — the grid can be tens of millions of cells
7374
/// on large bboxes, and the values are bounded to `[0, 1]` and only ever

0 commit comments

Comments
 (0)