Modern Apps git

← Modern-Apps.git

map: pin coastal terrain mask and coincident thinning

Commit
0d701a19b51f0f605fd3f75dd9146332ccb0ad68
Author
vayun-mathur <[email protected]>
When
2026-09-29 22:32 UTC (2 months ago)
Parents
a26d700

Diff

library/map/src/main/rust/src/tile/geometry/tests_extra7.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/tests_extra7.rs b/library/map/src/main/rust/src/tile/geometry/tests_extra7.rsindex d18da5262a..8111f06fd7 100644--- a/library/map/src/main/rust/src/tile/geometry/tests_extra7.rs+++ b/library/map/src/main/rust/src/tile/geometry/tests_extra7.rs@@ -208,3 +208,67 @@ fn terrain_height_is_normalised_from_the_dem() {         peak_m as f32 / ground as f32,     ); }++/// A coastal tile keeps relief off its water half: land on one side, lake water on+/// the other, one DEM. Cells reaching the water drop out while land cells stay —+/// so zooming into a coastline never paves the sea with shaded earth, whatever+/// the mainland polygon covers.+#[test]+fn a_coastal_tile_withholds_terrain_from_its_water_half() {+    use tilecodec::mamaps::dict::NONE;+    let layers = style::layers();+    let mut body = Body::new(4096);+    let mut landtype = BodyLayer::new(dict::LAYER_LANDTYPE);+    // Mainland west half; lake east half, sharing the x=2048 edge exactly — the+    // shape a clipped shoreline has in the tile.+    for (kind, x0) in [(NONE, 0), (crate::style::kind_id_for_test("lake"), 2048)] {+        landtype.features.push(Feature {+            kind,+            kind_detail: NONE,+            geom_type: GEOM_POLYGON,+            flags: 0,+            name_idx: NAME_NONE,+            parts_offset: landtype.parts.len() as u32,+            part_count: 1,+            transit_color: 0,+            transit_ordinal: 0,+            transit_lanes: 0,+            transit_taper: 0,+            lane_count: 0,+        });+        let base = landtype.coords.len() as u32;+        landtype.parts.push(Part {+            coord_start: base,+            point_count: 4,+            winding: WINDING_OUTER,+        });+        landtype.coords.extend_from_slice(&[+            (x0, 0),+            (x0 + 2048, 0),+            (x0 + 2048, 4096),+            (x0, 4096),+        ]);+    }+    body.layers.push(landtype);+    // Hilly DEM: relief must appear west, never east.+    body.heightmap = Some(heightmap(9, |c, r| (c as i32 + r as i32) * 20));+    let mesh = build(&body, &layers, 11, 339, 770, false);+    assert!(+        !mesh.terrain.indices.is_empty(),+        "the land half still builds relief"+    );+    // Every terrain triangle sits west of the shoreline (u < 0.5 in tile-local).+    for t in mesh.terrain.indices.chunks_exact(3) {+        for &i in t {+            let u = mesh.terrain.vertices[i as usize * terrain::FLOATS_PER_VERTEX];+            assert!(+                u < 0.5,+                "a terrain vertex at u={u} sits over the water half"+            );+        }+    }+    assert!(+        mesh_for(&mesh, &layers, "water").is_some(),+        "the water fill still draws flat over the withheld grid"+    );+}
scripts/maps/tile_build/tests/simplify_extra.rs
diff --git a/scripts/maps/tile_build/tests/simplify_extra.rs b/scripts/maps/tile_build/tests/simplify_extra.rsindex c0b72965da..db7601c985 100644--- a/scripts/maps/tile_build/tests/simplify_extra.rs+++ b/scripts/maps/tile_build/tests/simplify_extra.rs@@ -342,5 +342,34 @@ mod tests {             assert_eq!(kept(&small, tol), kept(&big, tol * 8.0), "at tolerance {tol}");         }     }++    /// A coincident shore and its water edge must thin to the SAME vertices, or the+    /// two drift apart and the renderer paints earth over sea between them. Both rings+    /// carry the same boundary crossings (ALWAYS), which the filter must respect.+    #[test]+    fn coincident_rings_thin_to_the_same_vertices() {+        use tile_build::clip::clip_ring;+        use tile_build::geom::Rect;+        // A land edge and a water edge sharing the segment x=0..20 at y=0.+        let rect = Rect { min_x: 0.0, min_y: -10.0, max_x: 20.0, max_y: 10.0 };+        let land = vec![(0.0, -10.0), (20.0, -10.0), (20.0, 0.0), (0.0, 0.0), (0.0, -10.0)];+        let water = vec![(0.0, 10.0), (20.0, 10.0), (20.0, 0.0), (0.0, 0.0), (0.0, 10.0)];+        let land_ring: Vec<SigPt> =+            clip_ring(&land.iter().map(|&(x, y)| SigPt::new(x, y)).collect::<Vec<_>>(), &rect);+        let water_ring: Vec<SigPt> =+            clip_ring(&water.iter().map(|&(x, y)| SigPt::new(x, y)).collect::<Vec<_>>(), &rect);+        let mut land_g = Geometry::Polygons(vec![vec![land_ring]]);+        let mut water_g = Geometry::Polygons(vec![vec![water_ring]]);+        annotate(&mut land_g);+        annotate(&mut water_g);+        let Geometry::Polygons(land_out) = filter(&land_g, 5.0) else { panic!() };+        let Geometry::Polygons(water_out) = filter(&water_g, 5.0) else { panic!() };+        // The shared edge y=0 survives identically in both: same vertices, so no+        // sliver opens between them at any zoom.+        let edge_of = |rings: &[Vec<Vec<SigPt>>]| -> Vec<Pt> {+            rings[0][0].iter().filter(|v| v.y == 0.0).map(|v| v.xy()).collect()+        };+        assert_eq!(edge_of(&land_out), edge_of(&water_out), "shared edge diverged");+    } }