Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / scripts / maps / mamaps_build / src / tiler_part10_s1.rs
tiler_part10_s1.rs157 lines · 7.7 KiBRaw
| 1 | /// **Phase B: a water tile with an island hole is drawable land and stays stored.** |
| 2 | /// The narrow check must not fire when the polygon carries a hole — that hole is an |
| 3 | /// island, and dropping the tile would delete land. |
| 4 | #[test] |
| 5 | fn a_water_tile_with_a_hole_stays_stored() { |
| 6 | // A sea square with a smaller land square punched out of its middle is modelled here |
| 7 | // as two features: the sea polygon plus a land-base polygon inside it. The tile |
| 8 | // covering both carries two features, so `is_water_background` refuses it. |
| 9 | let sea = Feature { |
| 10 | class: Class::area(dict::LAYER_LANDTYPE, crate::schema::kind("sea"), 0), |
| 11 | geometry: square(-10.0, -10.0, 20.0), |
| 12 | name: None, id: tilecodec::mamaps::body::ID_NONE, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, |
| 13 | turn_fwd: Vec::new(), |
| 14 | turn_bwd: Vec::new(), |
| 15 | building: None, |
| 16 | carriageway: tilecodec::mamaps::body::Carriageway::default(), |
| 17 | }; |
| 18 | let island = Feature { |
| 19 | class: Class::area(dict::LAYER_LANDTYPE, tilecodec::mamaps::dict::NONE, 0), |
| 20 | geometry: square(-1.0, -1.0, 2.0), |
| 21 | name: None, id: tilecodec::mamaps::body::ID_NONE, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, |
| 22 | turn_fwd: Vec::new(), |
| 23 | turn_bwd: Vec::new(), |
| 24 | building: None, |
| 25 | carriageway: tilecodec::mamaps::body::Carriageway::default(), |
| 26 | }; |
| 27 | let (bytes, _) = build(&spilled(&[sea, island]), &settings(0, 6)).expect("build"); |
| 28 | let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read"); |
| 29 | let mut saw_land = false; |
| 30 | for (_, _, body) in &entries { |
| 31 | let body = Body::parse(body).expect("parse"); |
| 32 | if let Some(layer) = body.layer(dict::LAYER_LANDTYPE) { |
| 33 | if layer.features.iter().any(|f| f.kind == tilecodec::mamaps::dict::NONE) { |
| 34 | saw_land = true; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | assert!(saw_land, "the island's land base must survive Phase B"); |
| 39 | } |
| 40 | |
| 41 | /// The wash-cap predicate, pinned without touching process-global state: |
| 42 | /// z14 landtype areas with `min_zoom != 14` drop; detail areas, all lines, |
| 43 | /// other layers and all other zooms survive. |
| 44 | #[test] |
| 45 | fn the_wash_cap_drops_only_z14_wash_areas() { |
| 46 | use tilecodec::mamaps::dict; |
| 47 | let lt = dict::LAYER_LANDTYPE; |
| 48 | // Wash areas drop at z14 whatever their min_zoom below the max. |
| 49 | for min_zoom in [0u8, 6, 8, 10, 13] { |
| 50 | assert!(super::wash_drops_kind(lt, true, min_zoom, 14), "min_zoom {min_zoom}"); |
| 51 | } |
| 52 | // Detail areas (min_zoom == max) survive: overzoom cannot recover them. |
| 53 | assert!(!super::wash_drops_kind(lt, true, 14, 14)); |
| 54 | // Lines survive at every zoom: cheap, high-salience, never wash. |
| 55 | assert!(!super::wash_drops_kind(lt, false, 0, 14)); |
| 56 | assert!(!super::wash_drops_kind(lt, false, 8, 14)); |
| 57 | // Other layers are untouched by the cap. |
| 58 | assert!(!super::wash_drops_kind(dict::LAYER_ROADS, true, 0, 14)); |
| 59 | assert!(!super::wash_drops_kind(dict::LAYER_BUILDINGS, true, 0, 14)); |
| 60 | // Every other zoom is untouched, including z13 (the overzoom source). |
| 61 | for z in [0u8, 6, 12, 13] { |
| 62 | assert!(!super::wash_drops_kind(lt, true, 0, z), "z{z}"); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /// The wash/detail partition is a schema fact, pinned so drift is |
| 67 | /// deliberate: exactly the six street-level area kinds sit at min_zoom 14. |
| 68 | #[test] |
| 69 | fn the_detail_kinds_are_exactly_the_minzoom_14_areas() { |
| 70 | use crate::schema::landtype; |
| 71 | let detail = ["swimming_pool", "dog_park", "playground", "pitch", "kindergarten", "platform"]; |
| 72 | for (key, value) in [ |
| 73 | ("leisure", "swimming_pool"), |
| 74 | ("leisure", "dog_park"), |
| 75 | ("leisure", "playground"), |
| 76 | ("leisure", "pitch"), |
| 77 | ("amenity", "kindergarten"), |
| 78 | ("public_transport", "platform"), |
| 79 | ] { |
| 80 | let tags: &[(&str, &str)] = &[(key, value)]; |
| 81 | let class = landtype::classify_late(tags).expect(value); |
| 82 | assert_eq!(class.min_zoom, 14, "{value} must be a detail kind"); |
| 83 | assert!(class.area); |
| 84 | } |
| 85 | // And the wash representatives sit below it (`natural=water` is an |
| 86 | // early rule — water is classified before roads — so it goes through |
| 87 | // `classify_early`; the rest are late). |
| 88 | for (key, value) in [ |
| 89 | ("natural", "wood"), |
| 90 | ("landuse", "farmland"), |
| 91 | ("leisure", "park"), |
| 92 | ("boundary", "national_park"), |
| 93 | ] { |
| 94 | let tags: &[(&str, &str)] = &[(key, value)]; |
| 95 | let class = landtype::classify_late(tags).expect(value); |
| 96 | assert!(class.min_zoom < 14, "{value} must be wash, not detail"); |
| 97 | } |
| 98 | { |
| 99 | let tags: &[(&str, &str)] = &[("natural", "water")]; |
| 100 | let class = landtype::classify_early(tags, true).expect("water"); |
| 101 | assert!(class.min_zoom < 14, "water must be wash, not detail"); |
| 102 | } |
| 103 | assert_eq!(detail.len(), 6); |
| 104 | } |
| 105 | |
| 106 | /// End to end: at z14 a wash lake is gone while a detail |
| 107 | /// pool and a river line survive; at z13 and below the lake is untouched. |
| 108 | #[test] |
| 109 | fn the_wash_cap_keeps_detail_and_lines_but_not_wash_at_z14() { |
| 110 | let pool = Feature { |
| 111 | class: Class::area(dict::LAYER_LANDTYPE, crate::schema::kind("swimming_pool"), 14), |
| 112 | geometry: square(-122.0, 37.0, 0.005), |
| 113 | name: None, id: tilecodec::mamaps::body::ID_NONE, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, |
| 114 | turn_fwd: Vec::new(), |
| 115 | turn_bwd: Vec::new(), |
| 116 | building: None, |
| 117 | carriageway: tilecodec::mamaps::body::Carriageway::default(), |
| 118 | }; |
| 119 | let river = Feature { |
| 120 | class: Class::line(dict::LAYER_LANDTYPE, crate::schema::kind("river"), 8), |
| 121 | geometry: Geometry::Lines(vec![vec![ |
| 122 | (-122.0, 37.0), |
| 123 | (-121.9, 37.1), |
| 124 | ]]), |
| 125 | name: None, id: tilecodec::mamaps::body::ID_NONE, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, |
| 126 | turn_fwd: Vec::new(), |
| 127 | turn_bwd: Vec::new(), |
| 128 | building: None, |
| 129 | carriageway: tilecodec::mamaps::body::Carriageway::default(), |
| 130 | }; |
| 131 | let features = vec![lake(-122.0, 37.0, 0.5, 0), pool, river]; |
| 132 | let (bytes, _) = build(&spilled(&features), &settings(0, 14)).expect("build"); |
| 133 | let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read"); |
| 134 | let kinds_at = |want_z: u8| { |
| 135 | let mut kinds = std::collections::BTreeSet::new(); |
| 136 | for (id, _, body) in &entries { |
| 137 | let (z, _, _) = tilecodec::pmtiles::tile_zxy(*id); |
| 138 | if z != want_z { |
| 139 | continue; |
| 140 | } |
| 141 | let body = Body::parse(body).expect("parse"); |
| 142 | if let Some(layer) = body.layer(dict::LAYER_LANDTYPE) { |
| 143 | kinds.extend(layer.features.iter().map(|f| f.kind)); |
| 144 | } |
| 145 | } |
| 146 | kinds |
| 147 | }; |
| 148 | let z14 = kinds_at(14); |
| 149 | let pool_id = crate::schema::kind("swimming_pool"); |
| 150 | let river_id = crate::schema::kind("river"); |
| 151 | let lake_id = crate::schema::kind("lake"); |
| 152 | assert!(z14.contains(&pool_id), "detail pool survives at z14"); |
| 153 | assert!(z14.contains(&river_id), "river line survives at z14"); |
| 154 | assert!(!z14.contains(&lake_id), "wash lake is gone at z14"); |
| 155 | let z13 = kinds_at(13); |
| 156 | assert!(z13.contains(&lake_id), "wash lake survives at z13"); |
| 157 | } |