library: map geometry queries no longer return polygon holes as filled features
- Commit
15a67f8ccbb04e2f5bf71a23b3c45ec567b46184- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 11:52 UTC (4 days ago)
- Parents
f7b478c
extract() emitted every polygon part as its own wire feature, ignoring winding: a building courtyard or a lake's island crossed as a standalone closed ring of the polygon kind, and consumers fill every closed ring — so the snapshot filled exactly the areas the polygon does not cover, disagreeing with the renderer (which tessellates exterior + holes as one group). A z1 fixture (building and lake, each with a hole) returned 2+2 features pre-fix, with hole points covering the courtyard centre where no building exists. extract now skips hole parts before conversion (they also no longer consume the point/feature caps); multipolygon exteriors are unaffected. Type docs now state exteriors- only on both sides of the wire; the wire itself is unchanged. Regression test pins building + lake holes. Tile/zoom maths and E7 round-trips were audited and cleared. Verified: cargo test -p map_renderer 574 passed plus integration suites; :library:map testDebugUnitTest + lint BUILD SUCCESSFUL.
Diff
library/map/src/main/java/com/vayunmathur/library/map/MapGeometry.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/MapGeometry.kt b/library/map/src/main/java/com/vayunmathur/library/map/MapGeometry.ktindex 21b224d88f..68fe92fc0d 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/MapGeometry.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/MapGeometry.kt@@ -42,8 +42,10 @@ enum class MapGeometryKind { } /**- * One extracted feature: a polyline, or one polygon ring/part when- * [closed]. [kindClass] is the feature's class (a road's highway class+ * One extracted feature: a polyline, or one polygon exterior ring/part+ * when [closed] (polygon holes are never returned: a hole filled as its+ * polygon's kind would paint a lake's island or a building's courtyard).+ * [kindClass] is the feature's class (a road's highway class * such as `residential`, else its kind name such as `lake`/`building`); * empty when the source feature carries neither. */
library/map/src/main/rust/src/tile/geometry_query.rs
diff --git a/library/map/src/main/rust/src/tile/geometry_query.rs b/library/map/src/main/rust/src/tile/geometry_query.rsindex e4f3762db7..4183642a3f 100644--- a/library/map/src/main/rust/src/tile/geometry_query.rs+++ b/library/map/src/main/rust/src/tile/geometry_query.rs@@ -102,7 +102,10 @@ const WATER_KINDS: [&str; 12] = [ /// line is a route across water/air, not a street. const NON_ROAD_KINDS: [&str; 3] = ["rail", "ferry", "aerialway"]; -/// One extracted feature: a polyline or one polygon ring/part.+/// One extracted feature: a polyline or one polygon exterior ring/part.+/// Polygon holes never become features (the wire has no hole flag and+/// consumers fill every closed ring, so a hole would fill its island or+/// courtyard with the polygon's kind). #[derive(Debug, Clone, PartialEq)] pub struct GeometryFeature { /// One of the `KIND_*` bits, as a single value (not a mask).@@ -185,12 +188,9 @@ fn tile_of(lat: f64, lon: f64, z: u8) -> (u32, u32) { let lat = lat.clamp(-85.051_128_78, 85.051_128_78); let x = ((lon + 180.0) / 360.0 * n).floor(); let lat_r = lat.to_radians();- let y = ((1.0 - (lat_r.tan() + 1.0 / lat_r.cos()).ln() / std::f64::consts::PI) / 2.0 * n)- .floor();- (- (x as u32).min(max),- (y as u32).min(max),- )+ let y =+ ((1.0 - (lat_r.tan() + 1.0 / lat_r.cos()).ln() / std::f64::consts::PI) / 2.0 * n).floor();+ ((x as u32).min(max), (y as u32).min(max)) } /// Tiles covering a bbox at `z`, centre-first (nearest tile centre to@@ -290,13 +290,26 @@ pub fn extract( None => continue, }; for part in layer.parts_of(feature) {+ // A polygon hole is absence, not geometry: the wire+ // carries no hole flag and the consumer fills every+ // closed ring it receives, so returning a hole as a+ // standalone feature would fill a building's+ // courtyard or a lake's island with that kind. Only+ // exterior rings cross; the renderer keeps holes+ // because its fill tessellator consumes the whole+ // ring group at once.+ if part.is_hole() {+ continue;+ } let raw = layer.points(part); if raw.len() < 2 { continue; } let points: Vec<(f64, f64)> = raw .iter()- .map(|&(px, py)| (point_lon(*tile, extent, px), point_lat(*tile, extent, py)))+ .map(|&(px, py)| {+ (point_lon(*tile, extent, px), point_lat(*tile, extent, py))+ }) .collect(); // Full parts only: a polygon cut to the bbox here // would lose its outside ring points and fill@@ -338,9 +351,7 @@ fn classify(want: u32, feature: &tilecodec::mamaps::body::Feature) -> Option<(u3 if (want == KIND_PATH) != is_path { return None; }- let class = detail_name(feature.kind_detail)- .unwrap_or(name)- .to_string();+ let class = detail_name(feature.kind_detail).unwrap_or(name).to_string(); Some((want, class)) } KIND_WATER => {@@ -474,8 +485,7 @@ pub fn query_geometry<T: TileSource>(source: &T, q: &GeometryQuery) -> GeometryR apply_wash_underlay(&mut pairs, &parents, &mut failed); } }- let refs: Vec<(TileId, Option<&Body>)> =- pairs.iter().map(|(t, b)| (*t, b.as_ref())).collect();+ let refs: Vec<(TileId, Option<&Body>)> = pairs.iter().map(|(t, b)| (*t, b.as_ref())).collect(); let mut out = extract(&refs, q, MAX_POINTS); out.failed_tiles = failed; out.truncated = out.truncated || stepped_out;
library/map/src/main/rust/src/tile/geometry_query/tests.rs
diff --git a/library/map/src/main/rust/src/tile/geometry_query/tests.rs b/library/map/src/main/rust/src/tile/geometry_query/tests.rsindex b34ea64110..8ca1477eb5 100644--- a/library/map/src/main/rust/src/tile/geometry_query/tests.rs+++ b/library/map/src/main/rust/src/tile/geometry_query/tests.rs@@ -1,5 +1,7 @@ use super::*;-use tilecodec::mamaps::body::{Feature, Layer as BodyLayer, Part, NAME_NONE, WINDING_OUTER};+use tilecodec::mamaps::body::{+ Feature, Layer as BodyLayer, Part, NAME_NONE, WINDING_HOLE, WINDING_OUTER,+}; use tilecodec::mamaps::dict::NONE; fn kind(name: &str) -> u16 {@@ -34,27 +36,61 @@ fn push(layer: &mut BodyLayer, mut f: Feature, pts: &[(i16, i16)]) { layer.features.push(f); } +/// Push one feature carrying several parts, each `(points, winding)`.+fn push_parts(layer: &mut BodyLayer, mut f: Feature, parts: &[(&[(i16, i16)], u16)]) {+ f.parts_offset = layer.parts.len() as u32;+ f.part_count = parts.len() as u32;+ for &(pts, winding) in parts {+ layer.parts.push(Part {+ coord_start: layer.coords.len() as u32,+ point_count: pts.len() as u32,+ winding,+ });+ layer.coords.extend_from_slice(pts);+ }+ layer.features.push(f);+}+ /// One tile at z1/0/0 (west-north quadrant): landtype lake, a road, /// a path, and a building, all in the tile's middle. fn body() -> Body { let mut body = Body::new(4096); let mut land = BodyLayer::new(LAYER_LANDTYPE); push(&mut land, feat(NONE, GEOM_POLYGON), &[(0, 0), (4096, 0), (4096, 4096), (0, 4096)]);- push(&mut land, feat(kind("lake"), GEOM_POLYGON), &[(2000, 2000), (3000, 2000), (3000, 3000), (2000, 3000)]);+ push(+ &mut land,+ feat(kind("lake"), GEOM_POLYGON),+ &[(2000, 2000), (3000, 2000), (3000, 3000), (2000, 3000)],+ ); body.layers.push(land); let mut roads = BodyLayer::new(LAYER_ROADS);- push(&mut roads, feat(kind("major_road"), GEOM_LINE), &[(500, 2000), (2000, 2000), (3500, 2000)]);+ push(+ &mut roads,+ feat(kind("major_road"), GEOM_LINE),+ &[(500, 2000), (2000, 2000), (3500, 2000)],+ ); push(&mut roads, feat(kind("path"), GEOM_LINE), &[(500, 2500), (3500, 2500)]); push(&mut roads, feat(kind("rail"), GEOM_LINE), &[(500, 3000), (3500, 3000)]); body.layers.push(roads); let mut buildings = BodyLayer::new(LAYER_BUILDINGS);- push(&mut buildings, feat(kind("building"), GEOM_POLYGON), &[(1000, 1000), (1500, 1000), (1500, 1500), (1000, 1500)]);+ push(+ &mut buildings,+ feat(kind("building"), GEOM_POLYGON),+ &[(1000, 1000), (1500, 1000), (1500, 1500), (1000, 1500)],+ ); body.layers.push(buildings); body } fn world() -> GeometryQuery {- GeometryQuery { west: -180.0, south: -85.0, east: 180.0, north: 85.0, kinds_mask: KIND_ALL, max_features: 256 }+ GeometryQuery {+ west: -180.0,+ south: -85.0,+ east: 180.0,+ north: 85.0,+ kinds_mask: KIND_ALL,+ max_features: 256,+ } } #[test]@@ -87,16 +123,82 @@ fn bbox_filtering_drops_features_outside_the_query() { // A bbox over the tile's far west edge: only the road/path // lines (which start at x=500) reach it; the lake/building do not. let (w, n) = (point_lon(tile, 4096, 600), point_lat(tile, 4096, 0));- let q = GeometryQuery { west: -180.0, south: 0.0, east: w, north: n, kinds_mask: KIND_ALL, max_features: 256 };+ let q = GeometryQuery {+ west: -180.0,+ south: 0.0,+ east: w,+ north: n,+ kinds_mask: KIND_ALL,+ max_features: 256,+ }; let out = extract(&[(tile, Some(&body))], &q, MAX_POINTS); assert!(out.features.iter().all(|f| f.kind == KIND_ROAD || f.kind == KIND_PATH)); // A bbox nowhere near the tile: honestly empty, still covered.- let q = GeometryQuery { west: 10.0, south: 10.0, east: 11.0, north: 11.0, kinds_mask: KIND_ALL, max_features: 256 };+ let q = GeometryQuery {+ west: 10.0,+ south: 10.0,+ east: 11.0,+ north: 11.0,+ kinds_mask: KIND_ALL,+ max_features: 256,+ }; let out = extract(&[(tile, Some(&body))], &q, MAX_POINTS); assert!(out.features.is_empty()); assert_eq!(out.covered_tiles, 1, "scanned and found nothing is not unavailable"); } +#[test]+fn polygon_holes_are_not_returned_as_filled_features() {+ // A building and a lake, each with a hole, on z1/0/0 (extent 4096).+ // Building exterior (1000,1000)-(3000,3000), hole+ // (1800,1800)-(2200,2200) whose centre (2000,2000) maps to+ // lon -92.109375, lat 67.339861: ground inside the hole is *not*+ // building, so returning the hole as a closed building fills it.+ let tile = TileId { z: 1, x: 0, y: 0 };+ let mut body = Body::new(4096);+ let mut buildings = BodyLayer::new(LAYER_BUILDINGS);+ push_parts(+ &mut buildings,+ feat(kind("building"), GEOM_POLYGON),+ &[+ (&[(1000, 1000), (3000, 1000), (3000, 3000), (1000, 3000)], WINDING_OUTER),+ (&[(1800, 1800), (2200, 1800), (2200, 2200), (1800, 2200)], WINDING_HOLE),+ ],+ );+ body.layers.push(buildings);+ let mut land = BodyLayer::new(LAYER_LANDTYPE);+ push_parts(+ &mut land,+ feat(kind("lake"), GEOM_POLYGON),+ &[+ (&[(500, 3100), (3500, 3100), (3500, 3900), (500, 3900)], WINDING_OUTER),+ (&[(1800, 3300), (2200, 3300), (2200, 3700), (1800, 3700)], WINDING_HOLE),+ ],+ );+ body.layers.push(land);+ let out = extract(&[(tile, Some(&body))], &world(), MAX_POINTS);+ let buildings: Vec<&GeometryFeature> =+ out.features.iter().filter(|f| f.kind == KIND_BUILDING).collect();+ assert_eq!(buildings.len(), 1, "only the exterior is building: {:?}", out.features);+ assert_eq!(buildings[0].points.len(), 4);+ assert_eq!(+ buildings[0].points[0],+ (point_lon(tile, 4096, 1000), point_lat(tile, 4096, 1000)),+ "the surviving ring is the exterior, starting at (-136.054688, 79.367701)"+ );+ // No returned building point comes from the hole ring: the hole's+ // first corner maps to (-100.898438, 70.495574).+ let hole_first = (point_lon(tile, 4096, 1800), point_lat(tile, 4096, 1800));+ assert!(+ !buildings[0].points.contains(&hole_first),+ "the hole ring must not cross as a filled building"+ );+ let water: Vec<&GeometryFeature> =+ out.features.iter().filter(|f| f.kind == KIND_WATER).collect();+ assert_eq!(water.len(), 1, "only the lake exterior is water: {:?}", out.features);+ assert_eq!(water[0].points.len(), 4);+}+ #[test] fn caps_truncate_whole_features_and_flag_it() { let tile = TileId { z: 1, x: 0, y: 0 };@@ -135,7 +237,11 @@ fn wash_underlay_stitches_parent_water_into_a_gated_child() { child_body.layers.push(roads); let mut parent_body = Body::new(4096); let mut land = BodyLayer::new(LAYER_LANDTYPE);- push(&mut land, feat(kind("lake"), GEOM_POLYGON), &[(0, 0), (2048, 0), (2048, 2048), (0, 2048)]);+ push(+ &mut land,+ feat(kind("lake"), GEOM_POLYGON),+ &[(0, 0), (2048, 0), (2048, 2048), (0, 2048)],+ ); parent_body.layers.push(land); assert!(crate::tile::geometry::needs_wash_underlay(&child_body, child.z)); let mut pairs = vec![(child, Some(child_body))];@@ -143,8 +249,7 @@ fn wash_underlay_stitches_parent_water_into_a_gated_child() { let mut failed = 0usize; apply_wash_underlay(&mut pairs, &parents, &mut failed); assert_eq!(failed, 0);- let refs: Vec<(TileId, Option<&Body>)> =- pairs.iter().map(|(t, b)| (*t, b.as_ref())).collect();+ let refs: Vec<(TileId, Option<&Body>)> = pairs.iter().map(|(t, b)| (*t, b.as_ref())).collect(); let out = extract(&refs, &world(), MAX_POINTS); let water: Vec<&GeometryFeature> = out.features.iter().filter(|f| f.kind == KIND_WATER).collect();@@ -189,7 +294,14 @@ fn tile_selection_and_zoom_are_bounded() { assert!(stepped); assert!(tiles_for_bbox(-180.0, -85.0, 180.0, 85.0, z).len() <= MAX_TILES); // A street bbox keeps the archive's deepest zoom.- let q = GeometryQuery { west: -0.001, south: 51.5, east: 0.001, north: 51.502, kinds_mask: KIND_ALL, max_features: 16 };+ let q = GeometryQuery {+ west: -0.001,+ south: 51.5,+ east: 0.001,+ north: 51.502,+ kinds_mask: KIND_ALL,+ max_features: 16,+ }; let (z, stepped) = choose_zoom(0, 14, &q); assert_eq!(z, 14); assert!(!stepped);