/// **The zoom-in island flooding, end to end.** Lake Superior at survey scale: /// a ~7°-wide lake through the real pipeline — classify (named → min_zoom 6), /// simplify, clip per tile, stage C — asserting the water survives at z0, z5 /// and z14. Before the area floor, an unnamed lake vanished below z12 and a /// named one below z6; the renderer then drew earth over the whole basin. /// /// Superior's real shoreline is thousands of vertices; ten per edge keeps the /// shape (and its tile-edge crossings) while the test stays instant. #[test] fn lake_superior_survives_coarse_and_fine() { use tilecodec::mamaps::body::Body; use tilecodec::mamaps::dict; // Lake Superior's real bbox (~-92.1..-84.4 lon, 46.4..48.9 lat), ten // vertices per edge: the tile-edge crossings are what the clipper and // stage C must survive, not the shoreline detail. let edge = |x0: f64, y0: f64, x1: f64, y1: f64| -> Vec<(f64, f64)> { (0..10) .map(|i| { let t = i as f64 / 9.0; (x0 + (x1 - x0) * t, y0 + (y1 - y0) * t) }) .collect() }; let (x0, y0, x1, y1) = (-92.1, 46.4, -84.4, 48.9); let mut ring = edge(x0, y0, x1, y0); ring.extend(edge(x1, y0, x1, y1).into_iter().skip(1)); ring.extend(edge(x1, y1, x0, y1).into_iter().skip(1)); ring.extend(edge(x0, y1, x0, y0).into_iter().skip(1)); // Classify exactly as a named lake classifies: min_zoom 0 start with an area // floor, which is what carries great water to the world tile. let tags: &[(&str, &str)] = &[("natural", "water"), ("water", "lake"), ("name", "Lake Superior")]; let class = crate::schema::landtype::classify_early(tags, true) .expect("a named lake classifies"); assert_eq!(class.min_zoom, 0, "the named-lake start zoom"); let features = vec![crate::extract::Feature { class, geometry: tile_build::geom::Geometry::Polygons(vec![vec![ring]]), name: None, id: tilecodec::mamaps::body::ID_NONE, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, turn_fwd: Vec::new(), turn_bwd: Vec::new(), carriageway: tilecodec::mamaps::body::Carriageway::default(), building: None, }]; let settings = crate::tiler::Settings { build_id: 1, scratch: std::env::temp_dir() .join(format!("mamaps_superior_{}.tilechunks", std::process::id())), force_chunk_spill_file: false, dem: crate::dem::Dem::from_grids(14, 17, Vec::new()), region_links: std::collections::HashMap::new(), country_zooms: std::collections::HashMap::new(), }; let store = crate::store::Store::of(&features).expect("spill"); let (bytes, _) = crate::tiler::build(&store, &settings).expect("build"); // A lake-kind polygon must be present at z0 (whole basin in a handful of // tiles), z5 and z14. Count tiles carrying any lake-kind feature. let mut saw = [false, false, false]; for (id, _, body) in tilecodec::mamaps::read::read_all(&bytes).expect("read") { let (z, _, _) = tilecodec::pmtiles::tile_zxy(id); let slot = match z { 0 => 0, 5 => 1, 14 => 2, _ => continue, }; let body = Body::parse(&body).expect("parse"); let Some(layer) = body.layer(dict::LAYER_LANDTYPE) else { continue; }; let lake_kind = crate::schema::kind("lake"); if layer.features.iter().any(|f| { f.geom_type == tilecodec::mamaps::body::GEOM_POLYGON && f.kind == lake_kind }) { saw[slot] = true; } } assert!(saw[0], " Superior water reaches z0"); assert!(saw[1], "Superior water reaches z5"); if crate::tiler::wash_cap_enabled() { assert!(!saw[2], "wash cap drops lake water at z14 (overzoomed from z13)"); } else { assert!(saw[2], "Superior water reaches z14"); } } /// **Country label gating, end to end.** Two `country` places through the real /// pipeline with scored start zooms: a Russia-scale label (z0) and a Vatican-scale /// label (z4). The z0 tile carries only Russia; the z4 tile carries both. A third /// unscored country keeps the schema floor and rides every zoom — a missing score /// must never hide a country. #[test] fn country_labels_start_at_their_scored_zoom() { use tilecodec::mamaps::body::Body; use tilecodec::mamaps::dict; fn country(id: u64) -> crate::extract::Feature { let class = crate::schema::places::classify( &[("place", "country"), ("name", "Test")] as &[(&str, &str)], ) .expect("classified"); crate::extract::Feature { class, geometry: tile_build::geom::Geometry::Points(vec![(10.0, 10.0)]), name: Some("Test".to_string()), id, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, turn_fwd: Vec::new(), turn_bwd: Vec::new(), carriageway: tilecodec::mamaps::body::Carriageway::default(), building: None, } } let russia = 1001u64; let vatican = 1002u64; let unscored = 1003u64; let features = vec![country(russia), country(vatican), country(unscored)]; let mut zooms: std::collections::HashMap = std::collections::HashMap::new(); zooms.insert(russia, 0); zooms.insert(vatican, 4); let settings = crate::tiler::Settings { build_id: 1, scratch: std::env::temp_dir() .join(format!("mamaps_countries_{}.tilechunks", std::process::id())), force_chunk_spill_file: false, dem: crate::dem::Dem::from_grids(14, 17, Vec::new()), region_links: std::collections::HashMap::new(), country_zooms: zooms, }; let store = crate::store::Store::of(&features).expect("spill"); let (bytes, _) = crate::tiler::build(&store, &settings).expect("build"); // Which ids does each zoom's `places` layer carry? let mut at_zoom: std::collections::HashMap> = std::collections::HashMap::new(); for (id, _, body) in tilecodec::mamaps::read::read_all(&bytes).expect("read") { let (z, _, _) = tilecodec::pmtiles::tile_zxy(id); if z != 0 && z != 4 { continue; } let body = Body::parse(&body).expect("parse"); let Some(layer) = body.layer(dict::LAYER_PLACES) else { continue; }; let country_kind = crate::schema::kind("country"); let has = |want: u64| { layer .features .iter() .enumerate() .filter(|(_, f)| f.kind == country_kind) .any(|(i, _)| body.feature_id(dict::LAYER_PLACES, i) == Some(want)) }; for want in [russia, vatican, unscored] { if has(want) { at_zoom.entry(z).or_default().push(want); } } } let mut z0 = at_zoom.get(&0).cloned().unwrap_or_default(); let mut z4 = at_zoom.get(&4).cloned().unwrap_or_default(); z0.sort_unstable(); z4.sort_unstable(); z0.dedup(); z4.dedup(); assert_eq!(z0, vec![russia, unscored], "z0 carries Russia and the unscored country"); assert_eq!( z4, vec![russia, vatican, unscored], "z4 carries all three — Vatican joins, nothing leaves" ); }