Modern Apps git

← Modern-Apps.git

mamaps: v10 default on + z13 landtype 3x + z14 road floor + mixed landtype

Commit
f49d648a4b4ed00627eec5ed2e9420e1d3962992
Author
vayun-mathur <[email protected]>
When
2026-10-14 17:17 UTC (1 month ago)
Parents
73f21fb
v10 flip (tiler gate default-on, MAMAPS_V8 escape hatch): narrowed
records (24B -> 12/17B), 4B parts, sparse S3DB/lanes/carriageways.
Device Body::parse already accepts v8/v9/v10; headers stay v9.

Mixed landtype records: polygons stay Min, named lines (rivers/canals
for curved labels) use Road via a 1-byte per-record tag. Uniform
layers untagged. Fixes the v10 river-name erasure the flip exposed.

z13 landtype wash 1.5x -> 3x (z14 stays 1.5x crisp): z13 spans ~5 km,
tripled tolerance is deep sub-pixel there.

z14 roads per-class floor 0.5u (needs_crisp: arterial or laned/split
or one-way keeps 0.0; residential/service take the floor).

Building vertex grid 2u after snap (hand jitter -> repeated consts).

273 tests pass (order test now counts on kind, which Min keeps).

Diff

library/tilecodec/src/main/rust/src/mamaps/body/codec.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body/codec.rs b/library/tilecodec/src/main/rust/src/mamaps/body/codec.rsindex de42215152..7eb64a3e20 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body/codec.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body/codec.rs@@ -426,21 +426,45 @@ fn parse_layer_v8(layer_id: u8, feature_count: usize, buf: &[u8]) -> Result<Laye /// the arena walk — v10 parts are validated contiguous exactly as v8 requires. pub(crate) fn parse_layer_v10(layer_id: u8, feature_count: usize, buf: &[u8]) -> Result<Layer> {     use super::consts::{FEATURE_RECORD_MIN_LEN, FEATURE_RECORD_ROAD_LEN, PART_ENTRY_V10_LEN};-    use super::emit_extra::{RecordClass, record_class};+    use super::emit_extra::{RecordClass, is_mixed_layer, record_class};     let class = record_class(layer_id);-    let reclen = match class {-        RecordClass::Min => FEATURE_RECORD_MIN_LEN,-        RecordClass::Road => FEATURE_RECORD_ROAD_LEN,-        RecordClass::Full => FEATURE_RECORD_LEN,-    };-    let features_len = feature_count * reclen;-    if features_len > buf.len() {-        return err("a .mamaps layer's features run past its payload");-    }+    let mixed = is_mixed_layer(layer_id);+    // Uniform layers stride fixed-width records; mixed layers walk a tag+    // byte per record (0 = Min, 1 = Road) so named lines keep their names.     let mut features = Vec::with_capacity(feature_count);     let mut parts_needed = 0usize;-    for i in 0..feature_count {-        let at = i * reclen;+    let mut at = 0usize;+    for _ in 0..feature_count {+        let feature_class = if mixed {+            if at + 1 > buf.len() {+                return err("a .mamaps mixed-layer record ends inside its class tag");+            }+            let wide = match buf[at] {+                0 => false,+                1 => true,+                t => {+                    return err(format!(+                        "a .mamaps mixed-layer record has class tag {t}, which this format does not carry"+                    ));+                }+            };+            at += 1;+            if wide {+                RecordClass::Road+            } else {+                RecordClass::Min+            }+        } else {+            class+        };+        let reclen = match feature_class {+            RecordClass::Min => FEATURE_RECORD_MIN_LEN,+            RecordClass::Road => FEATURE_RECORD_ROAD_LEN,+            RecordClass::Full => FEATURE_RECORD_LEN,+        };+        if at + reclen > buf.len() {+            return err("a .mamaps layer's features run past its payload");+        }         let u16_at = |o: usize| u16::from_le_bytes([buf[at + o], buf[at + o + 1]]);         let u32_at = |o: usize| {             u32::from_le_bytes([buf[at + o], buf[at + o + 1], buf[at + o + 2], buf[at + o + 3]])@@ -450,7 +474,7 @@ pub(crate) fn parse_layer_v10(layer_id: u8, feature_count: usize, buf: &[u8]) ->         // emit order: kind, [detail,] geom, flags, [name,] off, cnt, [lane].         let (kind_detail, name_idx, lane_count, transit);         let (geom_type, flags, parts_offset, part_count);-        match class {+        match feature_class {             RecordClass::Min => {                 kind_detail = 0;                 name_idx = NAME_NONE;@@ -510,9 +534,10 @@ pub(crate) fn parse_layer_v10(layer_id: u8, feature_count: usize, buf: &[u8]) ->             .ok_or_else(|| crate::proto::Error("a .mamaps feature's parts overflow".to_string()))?;         parts_needed = parts_needed.max(end);         features.push(feature);+        at += reclen;     } -    let parts_at = features_len;+    let parts_at = at;     let parts_len = parts_needed * PART_ENTRY_V10_LEN;     if parts_at + parts_len > buf.len() {         return err("a .mamaps layer's parts run past its payload");
library/tilecodec/src/main/rust/src/mamaps/body/emit_extra.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body/emit_extra.rs b/library/tilecodec/src/main/rust/src/mamaps/body/emit_extra.rsindex 6216df0f78..773923e8a8 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body/emit_extra.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body/emit_extra.rs@@ -59,6 +59,17 @@ pub(crate) fn record_class(layer_id: u8) -> RecordClass {     } } +/// Whether a layer mixes Min and Road records per feature under v10.+///+/// Landtype is the only mixed layer: polygons (the overwhelming majority)+/// carry no names or details and use Min, while named lines (rivers, canals+/// — curved-label carriers) use Road. Each record is prefixed with a 1-byte+/// tag (0 = Min, 1 = Road). Every other layer is uniform per `record_class`+/// and carries no tag.+pub(crate) fn is_mixed_layer(layer_id: u8) -> bool {+    layer_id == dict::LAYER_LANDTYPE+}+ /// One layer's full v7 payload bytes: features, part table, align4, arena. /// /// Factored out of [`super::emit::serialize_into`] so the emit path has one@@ -143,8 +154,23 @@ pub(crate) fn write_v10_layer_payload(         // than silently discarding them. The tiler never sets transit bytes         // on non-transit layers (or names/details/lanes where the class has         // none), so this fires only on a caller bug, never on real tiles.+        //+        // Mixed layers (landtype) prefix each record with a 1-byte tag so+        // the parser can stride: 0 = Min, 1 = Road. Uniform layers carry no+        // tag; their class comes from `record_class`.+        let feature_class = if is_mixed_layer(layer.layer_id) {+            let wide = feature.name_idx != super::model::NAME_NONE;+            out.push(u8::from(wide));+            if wide {+                RecordClass::Road+            } else {+                RecordClass::Min+            }+        } else {+            class+        };         out.extend_from_slice(&feature.kind.to_le_bytes());-        match class {+        match feature_class {             RecordClass::Min => {                 if feature.kind_detail != 0                     || feature.name_idx != super::model::NAME_NONE
scripts/maps/mamaps_build/src/tiler.rs
diff --git a/scripts/maps/mamaps_build/src/tiler.rs b/scripts/maps/mamaps_build/src/tiler.rsindex 5d7a4c75e1..25be47f1f1 100644--- a/scripts/maps/mamaps_build/src/tiler.rs+++ b/scripts/maps/mamaps_build/src/tiler.rs@@ -131,10 +131,16 @@ pub const WASH_SIMPLIFICATION: f64 = 1.5;  /// Extra simplification for the landtype wash: natural boundaries are looked /// at closer than admin ones, so the factor stays at the wash level rather-/// than above it. Same mechanism as [`WASH_SIMPLIFICATION`], own constant so-/// the two tune independently.+/// than above it — except at z13, where a tile spans ~5 km and even tripled+/// tolerance is deep sub-pixel. Same mechanism as [`WASH_SIMPLIFICATION`],+/// own constants so the two zooms tune independently. pub const LANDTYPE_SIMPLIFICATION: f64 = 1.5; +/// The z13 landtype factor: forest edges, shorelines and farmland at 3x the+/// per-zoom policy tolerance. z14 stays at 1.5x (crisp parks under streets);+/// z13 is viewed from high, where a ~4 m tolerance is a fraction of a pixel.+pub const LANDTYPE_Z13_SIMPLIFICATION: f64 = 3.0;+ /// The simplification floor for the `buildings` layer, in extent units. /// /// Buildings live only at z14 and up, where [`simplify::tolerance_for`] is 0.0 at max zoom@@ -144,6 +150,54 @@ pub const LANDTYPE_SIMPLIFICATION: f64 = 1.5; /// prototype at `analysis/mamaps_building_savings.py` estimates ~2% of building-tile bytes. pub const BUILDING_TOLERANCE: f64 = 0.5; +/// The simplification floor for washable `roads` at the archive max, in extent units.+///+/// z14 policy tolerance is 0.0 (full detail for carriageway/lane alignment), but only+/// a minority of roads needs it: arterials, and roads carrying lane masks or a+/// carriageway split, whose centre line the renderer places from geometry (see+/// `needs_crisp`). A residential street's centre line has no such reader — a+/// half-unit floor drops only collinear midpoints and sub-pixel jaggies,+/// invisible at z14 where 16 units are a display pixel. Same magnitude as+/// [`BUILDING_TOLERANCE`] for the same reason.+pub const ROAD_DETAIL_FLOOR: f64 = 0.5;++/// True when a road's geometry must stay exactly as digitised: an arterial+/// (motorway through tertiary, mainlines and `_link`s), or any road carrying+/// lane masks, a lane count, or a non-default carriageway split — the only+/// roads whose centre-line placement reads geometry. Everything else+/// (residential, service, track, path…) takes [`ROAD_DETAIL_FLOOR`] at z14:+/// a principled rule about readers, not a cap.+fn needs_crisp(feature: &crate::extract::Feature) -> bool {+    use tilecodec::mamaps::body::FLAG_IS_ONEWAY;+    // Arterials by interned kind_detail id: the HIGHWAYS table's+    // motorway→tertiary rows (schema/roads.rs). Links share the rule: a+    // motorway_link's curve places the same carriageway its mainline does.+    // Built once (read-only after init, so deterministic across threads).+    static ARTERIALS: std::sync::OnceLock<std::collections::HashSet<u16>> =+        std::sync::OnceLock::new();+    let arterials = ARTERIALS.get_or_init(|| {+        [+            "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link",+            "secondary", "secondary_link", "tertiary", "tertiary_link",+        ]+        .into_iter()+        .map(crate::schema::detail)+        .collect()+    });+    if arterials.contains(&feature.class.kind_detail) {+        return true;+    }+    if feature.lane_count > 0 || !feature.turn_fwd.is_empty() || !feature.turn_bwd.is_empty() {+        return true;+    }+    if !feature.carriageway.is_empty() {+        return true;+    }+    // A one-way's digitising direction is its semantics; simplification+    // preserves endpoints but can bow the line, so keep it crisp.+    feature.class.flags & FLAG_IS_ONEWAY != 0+}+ /// The orthogonal-snap tolerance for building rings, in extent units. /// /// Edges within half a unit of axis-aligned are snapped exactly so (see@@ -154,6 +208,14 @@ pub const BUILDING_TOLERANCE: f64 = 0.5; /// thread count and chunk boundaries like everything else in [`tile_chunk`]. pub const BUILDING_SNAP: f64 = 0.5; +/// The building vertex grid: coordinates round to multiples of this (extent+/// units) after snapping. 2 units ≈ 1.2 m / ~1/8 display pixel at z14 —+/// invisible natively, and hand-digitised jitter collapses into repeated+/// constants the varint arena and DEFLATE dictionary encode cheaply. Runs+/// inside the snap (same survivors-only pass, significance untouched), so it+/// inherits the determinism property.+pub const BUILDING_GRID: f64 = 2.0;+ /// Input vertices per chunk handed to one worker. /// /// By **vertex** rather than by feature, because feature cost spans four orders of magnitude in the
scripts/maps/mamaps_build/src/tiler_part10.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part10.rs b/scripts/maps/mamaps_build/src/tiler_part10.rsindex 61a2b246ed..6348571848 100644--- a/scripts/maps/mamaps_build/src/tiler_part10.rs+++ b/scripts/maps/mamaps_build/src/tiler_part10.rs@@ -188,8 +188,9 @@ mod tests_part10 {     /// This is the failure the whole module is arranged around, and it is invisible from outside: a     /// merge that folded chunks in completion order would still put every feature in the right tile,     /// still draw the right picture, and still write different bytes every run. So each feature-    /// carries a `kind_detail` counting up in store order, and the decoded archive has to count up-    /// too.+    /// carries a `kind` counting up in store order, and the decoded archive has to count up+    /// too. (`kind`, not `kind_detail`: v10 minimal records drop detail, so the+    /// counter must ride in a surviving field.)     #[test]     fn feature_order_within_a_tile_layer_is_the_store_order() {         let _budget = budget();@@ -198,7 +199,7 @@ mod tests_part10 {         let features: Vec<Feature> = (0..40u16)             .map(|i| Feature {                 class: Class {-                    kind_detail: i,+                    kind: 1000 + i,                     ..Class::area(dict::LAYER_LANDTYPE, crate::schema::kind("lake"), 0)                 },                 geometry: square(-120.0 + i as f64 * 0.00005, 35.0, 0.004),@@ -221,7 +222,7 @@ mod tests_part10 {         for (id, _, body) in &entries {             let body = Body::parse(body).expect("parse");             let Some(layer) = body.layer(dict::LAYER_LANDTYPE) else { continue };-            let order: Vec<u16> = layer.features.iter().map(|f| f.kind_detail).collect();+            let order: Vec<u16> = layer.features.iter().map(|f| f.kind).collect();             let mut ascending = order.clone();             ascending.sort_unstable();             assert_eq!(order, ascending, "tile {id} holds its features out of store order");
scripts/maps/mamaps_build/src/tiler_part2.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part2.rs b/scripts/maps/mamaps_build/src/tiler_part2.rsindex 3ea23bb38f..e71ac9da03 100644--- a/scripts/maps/mamaps_build/src/tiler_part2.rs+++ b/scripts/maps/mamaps_build/src/tiler_part2.rs@@ -333,7 +333,8 @@ fn tile_chunk(         simplify::annotate(&mut projected);         // Buildings live only at z14, where the policy tolerance is 0.0; the floor below         // keeps only collinear midpoints and sub-pixel jaggies — see `tolerance_for_layer`.-        let layer_tolerance = tolerance_for_layer(feature.class.layer, z, tolerance);+        // Roads take the per-feature floor at z14 (washable classes only).+        let layer_tolerance = tolerance_for_feature(feature, z, tolerance);         let thinned = simplify::filter(&projected, layer_tolerance);         // Near-rectangles digitised by hand gain a cheap varint delta when their edges snap         // exactly axis-aligned — see `snap_building_rings`. Survivors only, so the measured@@ -398,7 +399,13 @@ fn tolerance_for_layer(layer: u8, z: u8, tolerance: f64) -> f64 {     } else if layer == dict::LAYER_BOUNDARIES {         tolerance * WASH_SIMPLIFICATION     } else if layer == dict::LAYER_LANDTYPE {-        tolerance * LANDTYPE_SIMPLIFICATION+        // z13 tiles span ~5 km: triple the wash there, keep 1.5x at z14+        // where parks sit under streets.+        if z == 13 {+            tolerance * LANDTYPE_Z13_SIMPLIFICATION+        } else {+            tolerance * LANDTYPE_SIMPLIFICATION+        }     } else if z < crate::DEFAULT_MAX_ZOOM         && (layer == dict::LAYER_ROADS || layer == dict::LAYER_TRANSIT)     {@@ -410,6 +417,23 @@ fn tolerance_for_layer(layer: u8, z: u8, tolerance: f64) -> f64 {     } } +/// The tolerance for one feature: the layer policy, plus the z14 roads+/// floor. Washable roads (not arterial, no lanes/split — see `needs_crisp`)+/// take [`ROAD_DETAIL_FLOOR`] at the archive max, where the layer policy is+/// 0.0; everything else keeps the layer value untouched.+fn tolerance_for_feature(feature: &crate::extract::Feature, z: u8, tolerance: f64) -> f64 {+    use tilecodec::mamaps::dict;+    let base = tolerance_for_layer(feature.class.layer, z, tolerance);+    if z == crate::DEFAULT_MAX_ZOOM+        && feature.class.layer == dict::LAYER_ROADS+        && !needs_crisp(feature)+    {+        base.max(ROAD_DETAIL_FLOOR)+    } else {+        base+    }+}+ /// Snap a building geometry's near-axis-aligned edges to exactly axis-aligned. /// /// Hand-digitised footprints are near-rectangles: edges within [`BUILDING_SNAP`] of horizontal@@ -474,7 +498,14 @@ fn snap_building_ring(ring: &[SigPt]) -> Vec<SigPt> {     let mut out: Vec<SigPt> = open         .iter()         .zip(snapped)-        .map(|(v, (x, y))| v.moved((x, y)))+        .map(|(v, (x, y))| {+            // Round onto the building grid: hand jitter (±1 unit) collapses+            // into repeated constants. Runs here — after the filter, on+            // survivors only — so measured significance is never stale.+            let gx = (x / crate::tiler::BUILDING_GRID).round() * crate::tiler::BUILDING_GRID;+            let gy = (y / crate::tiler::BUILDING_GRID).round() * crate::tiler::BUILDING_GRID;+            v.moved((gx, gy))+        })         .collect();     if closed {         out.push(out[0]);
scripts/maps/mamaps_build/src/tiler_part5.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part5.rs b/scripts/maps/mamaps_build/src/tiler_part5.rsindex 11c59c76c6..64c98eb454 100644--- a/scripts/maps/mamaps_build/src/tiler_part5.rs+++ b/scripts/maps/mamaps_build/src/tiler_part5.rs@@ -294,13 +294,14 @@ fn encode_tile(         region_links: region_links_table,     };     let encoded_body = timed(on, &SERIALIZE_NANOS, || {-        // v10 narrowed records behind `MAMAPS_V10=1` until the side tables-        // land and the default flips. Same geometry either way — only the-        // fixed records shrink — so this gate changes bytes, never shapes.-        if std::env::var("MAMAPS_V10").is_ok() {-            tilecodec::mamaps::body::serialize_into_v10(&body, scratch)-        } else {+        // v10 narrowed records + sparse side tables are the default: same+        // geometry either way — only the fixed records shrink — so this+        // changes bytes, never shapes. `MAMAPS_V8=1` opts back out to the+        // dense v8 bodies (escape hatch for bisecting a suspect build).+        if std::env::var("MAMAPS_V8").is_ok() {             tilecodec::mamaps::body::serialize_into(&body, scratch)+        } else {+            tilecodec::mamaps::body::serialize_into_v10(&body, scratch)         }     })?;     let raw_len = encoded_body.len();
scripts/maps/mamaps_build/src/tiler_part7.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part7.rs b/scripts/maps/mamaps_build/src/tiler_part7.rsindex 4b7b010f51..960f83a201 100644--- a/scripts/maps/mamaps_build/src/tiler_part7.rs+++ b/scripts/maps/mamaps_build/src/tiler_part7.rs@@ -187,7 +187,7 @@ mod tests {         assert_eq!(tolerance_for_layer(dict::LAYER_BUILDINGS, 14, 2.0), 2.0);         // And below the buildings floor the policy stands: z13 keeps 1.0, not 0.5.         assert_eq!(tolerance_for_layer(dict::LAYER_BUILDINGS, 13, 1.0), 1.0);-        assert_eq!(tolerance_for_layer(dict::LAYER_LANDTYPE, 13, 1.0), 1.5, "the landtype wash scales the policy");+        assert_eq!(tolerance_for_layer(dict::LAYER_LANDTYPE, 13, 1.0), 3.0, "z13 landtype triples the wash");         // Roads take the wash below the archive max (z13 1.5x); at z14 policy         // is 0.0 and the wash is a no-op — crisp where lanes align.         assert_eq!(tolerance_for_layer(dict::LAYER_ROADS, 13, 1.0), 1.5, "roads wash below max zoom");