Modern Apps git

← Modern-Apps.git

maps: road widths track ground at high zoom; right U-turn glyph

Commit
10c2938be4f31cb5074127f060bb662ab54843fb
Author
vayun-mathur <[email protected]>
When
2026-09-11 18:35 UTC (2 months ago)
Parents
28a82f3

Diff

library/map/src/main/rust/src/style/mod.rs
diff --git a/library/map/src/main/rust/src/style/mod.rs b/library/map/src/main/rust/src/style/mod.rsindex 87a000af4b..c15e236802 100644--- a/library/map/src/main/rust/src/style/mod.rs+++ b/library/map/src/main/rust/src/style/mod.rs@@ -689,6 +689,10 @@ pub fn background(variant: Variant) -> u32 { /// painted markings, the `junction-connector` surface that continues it through an intersection, /// the carriageway taper, and the road-surface turn arrows. Off for release; the code stays. ///+/// **This is the map surface, not the navigation lane guidance bar.** The two share the word+/// "lane" and nothing else: the guidance bar is a Compose overlay fed by the router's per-step+/// lane data, it has no connection to a style layer, and it draws whatever this says. Do not+/// read a blank map surface as the guidance bar being off, or vice versa. /// It works by dropping the two [`Layer::carriageway`] layers from [`layers`], which is the one /// point every part of the feature already funnels through. No carriageway layer means /// `tile::geometry`'s carriageway branch is never taken (so no ribbon mesh, no taper), and
library/map/src/main/rust/src/style/paint.rs
diff --git a/library/map/src/main/rust/src/style/paint.rs b/library/map/src/main/rust/src/style/paint.rsindex b485e0376b..646770b2ee 100644--- a/library/map/src/main/rust/src/style/paint.rs+++ b/library/map/src/main/rust/src/style/paint.rs@@ -1383,6 +1383,101 @@ mod tests {         authored_ramp(json)     } +    /// The ramps whose width tracks a fixed **ground** width above the zoom upstream stops at.+    ///+    /// `basemap.json` clamps these at their last stop — z18 for most, z20 for a few — because a+    /// MapLibre style is written for a camera that stops there. Ours does not: the renderer+    /// overzooms to [`MAX_ZOOM`], and a clamped ramp holds its Dp width while the ground halves+    /// under it, so a road 3.9 m wide at z18 is 0.24 m wide at z22. The carriageway surface used+    /// to cover that whole range, but [`super::LANE_RENDERING`] is off for release and drops it,+    /// leaving these layers as the only thing drawing a road at z16+. Above the clamp each stop+    /// doubles, which is the rate the ground shrinks, so the road keeps the width it had there.+    ///+    /// Enumerated layer by layer and property by property rather than matched by a rule over+    /// ids: this is the only place the flat style is allowed to say more about a line's width+    /// than the authored file does, so it has to be a list a reader can check. Every other+    /// property on these layers, and every property on every other layer, stays pinned.+    ///+    /// A casing carries both halves. `gap_width` is the clear span the fill sits in and `width`+    /// is the thickness of each band beside it, so extending one without the other would leave+    /// the outline stranded inside a road sixteen times wider than the gap it was drawn around.+    ///+    /// `roads-rail` is deliberately absent: it is not a road, and a rail line is a symbol whose+    /// width says "there is a railway here" rather than how wide the track is.+    const FIXED_GROUND_WIDTH: &[(&str, &str, f64)] = &[+        ("roads-minor-casing", "width", 18.0),+        ("roads-minor-casing", "gap_width", 18.0),+        ("roads-major-casing", "width", 18.0),+        ("roads-major-casing", "gap_width", 18.0),+        ("roads-highway-casing", "width", 20.0),+        ("roads-highway-casing", "gap_width", 18.0),+        ("roads-link-casing", "width", 18.0),+        ("roads-link-casing", "gap_width", 18.0),+        ("roads-bridges-highway-casing", "width", 20.0),+        ("roads-bridges-highway-casing", "gap_width", 18.0),+        ("roads-bridges-major-casing", "width", 18.0),+        ("roads-bridges-major-casing", "gap_width", 18.0),+        ("roads-bridges-minor-casing", "width", 18.0),+        ("roads-bridges-minor-casing", "gap_width", 18.0),+        ("roads-bridges-link-casing", "width", 18.0),+        ("roads-bridges-link-casing", "gap_width", 18.0),+        ("roads-bridges-other-casing", "width", 20.0),+        ("roads-bridges-other-casing", "gap_width", 20.0),+        ("roads-path", "width", 20.0),+        ("roads-minor", "width", 18.0),+        ("roads-major", "width", 18.0),+        ("roads-highway", "width", 18.0),+        ("roads-link", "width", 18.0),+        ("roads-bridges-highway", "width", 18.0),+        ("roads-bridges-major", "width", 18.0),+        ("roads-bridges-minor", "width", 18.0),+        ("roads-bridges-link", "width", 18.0),+        ("roads-bridges-other", "width", 20.0),+        ("roads-minor-service", "width", 18.0),+    ];++    /// The zoom [`FIXED_GROUND_WIDTH`] tabulates for a ramp, or `None` if it is not one.+    fn fixed_ground_width_anchor(id: &str, property: &str) -> Option<f64> {+        FIXED_GROUND_WIDTH+            .iter()+            .find(|(layer, prop, _)| *layer == id && *prop == property)+            .map(|(_, _, anchor)| *anchor)+    }++    /// An authored ramp carrying the doubling tail the flat file is expected to add to it.+    ///+    /// Extended here, from the authored ramp, rather than hand-copied into `basemap.json`: that+    /// file is a vendored copy of Protomaps' style, and writing our stops into it would both+    /// falsify the copy and leave this comparison checking one hand transcription against+    /// another — which is the failure the cross-check exists to catch. Reading upstream and+    /// applying one stated rule keeps every value below the clamp pinned to the source, and+    /// makes the values above it a consequence of a rule rather than 80 more typed numbers.+    fn extended_to_fixed_ground_width(id: &str, property: &str, authored: &Ramp) -> Ramp {+        let Some(anchor) = fixed_ground_width_anchor(id, property) else {+            return authored.clone();+        };+        let last = authored.stops[authored.stops.len() - 1].0;+        // Catches a vendor refresh that moves the clamp: upstream deciding a road grows until+        // z19 would otherwise be silently overwritten by a tail anchored at the old zoom.+        assert_eq!(+            anchor,+            last.max(18.0),+            "`{id}`'s {property} is tabulated as extending from z{anchor}, but basemap.json \+             clamps it at z{last} — upstream moved and the table has to move with it",+        );+        let value = authored.at(anchor);+        let mut stops = authored.stops.clone();+        if last < anchor {+            stops.push((anchor, value));+        }+        let mut zoom = anchor + 1.0;+        while zoom <= MAX_ZOOM as f64 {+            stops.push((zoom, value * 2.0f32.powf((zoom - anchor) as f32)));+            zoom += 1.0;+        }+        Ramp { base: authored.base, stops }+    }+     /// **The mitigation for the one risk this module has a history of.** Hand-transcribing     /// `basemap.json` failed twice before, so every value that exists in both files is compared     /// here and divergence fails a build rather than being noticed on a screenshot.@@ -1463,10 +1558,13 @@ mod tests {                         .and_then(|p| p.get("line-width"))                         .is_some();                     if authored_has_width && layer.toggle != Some(Toggle::Transit) {+                        let width =+                            extended_to_fixed_ground_width(&layer.id, "width", &width);                         assert_ramps_agree(&layer.id, "width", &layer.width, &width);                     }                     let gap = authored_property(&authored, "line-gap-width")                         .unwrap_or_else(|| Ramp::constant(0.0));+                    let gap = extended_to_fixed_ground_width(&layer.id, "gap_width", &gap);                     assert_ramps_agree(&layer.id, "gap_width", &layer.gap_width, &gap);                 }                 LayerKind::Symbol => {@@ -1519,18 +1617,62 @@ mod tests {         }     } +    /// Above its clamp a road's stroke doubles with every zoom, which is what holds the road a+    /// fixed width **on the ground** while the ground halves under it.+    ///+    /// A ratio against a tolerance rather than an equality on the values: the stops are `f32`+    /// and are read back through the ramp's exponential interpolation, so asserting an exact+    /// number would be a test that passes by luck and fails on a rounding change. The ratio is+    /// also the property that actually matters — it is what "fixed ground width" *means*, and+    /// it stays true no matter what the anchor value is or which layer carries it.+    #[test]+    fn a_road_stroke_doubles_with_every_zoom_above_its_clamp() {+        for (id, property, anchor) in FIXED_GROUND_WIDTH {+            let layer = find(id);+            let ramp = match *property {+                "width" => &layer.width,+                "gap_width" => &layer.gap_width,+                other => panic!("`{id}` is tabulated with an unknown property `{other}`"),+            };+            let mut zoom = *anchor;+            while zoom + 1.0 <= MAX_ZOOM as f64 {+                let (lower, upper) = (ramp.at(zoom), ramp.at(zoom + 1.0));+                assert!(+                    lower > 0.0,+                    "`{id}`'s {property} is 0 at z{zoom}, so it has no width to double",+                );+                let ratio = upper / lower;+                assert!(+                    (ratio - 2.0).abs() < 1e-3,+                    "`{id}`'s {property} goes {lower} -> {upper} across z{zoom}..z{}, a ratio of \+                     {ratio} where holding a fixed ground width needs 2",+                    zoom + 1.0,+                );+                zoom += 1.0;+            }+        }+    }+     /// Two ramps must agree at every tenth of a zoom, not merely stop for stop.     ///     /// Comparing evaluated values rather than the stop lists is what lets a constant and a     /// one-stop ramp compare equal, and it is also the thing that actually matters: a stop     /// written at a different zoom with a compensating value is still the same paint.     fn assert_ramps_agree(id: &str, property: &str, flat: &Ramp, authored: &Ramp) {+        let anchor = fixed_ground_width_anchor(id, property);         for tenth in 0..=(MAX_ZOOM as u32 * 10) {             let zoom = tenth as f64 / 10.0;             let (ours, theirs) = (flat.at(zoom), authored.at(zoom));+            // Above the clamp the expected value is upstream's *extended* by+            // `FIXED_GROUND_WIDTH`, not something `basemap.json` states, and saying otherwise+            // would send whoever reads this looking for a stop that is not there.+            let source = match anchor {+                Some(anchor) if zoom > anchor => "basemap.json extended to a fixed ground width",+                _ => "basemap.json",+            };             assert!(                 (ours - theirs).abs() < 1e-5,-                "`{id}`'s {property} is {ours} at z{zoom} where basemap.json says {theirs}",+                "`{id}`'s {property} is {ours} at z{zoom} where {source} says {theirs}",             );         }     }
library/map/src/main/rust/style/basemap.flat.json
diff --git a/library/map/src/main/rust/style/basemap.flat.json b/library/map/src/main/rust/style/basemap.flat.jsonindex e20731f659..80e40e4ede 100644--- a/library/map/src/main/rust/style/basemap.flat.json+++ b/library/map/src/main/rust/style/basemap.flat.json@@ -245,11 +245,15 @@       "forbid_details": ["service"],       "light": "#e0e0e0",       "dark": "#111318",-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[12, 0], [12.5, 1]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[12, 0], [12.5, 1], [18, 1], [19, 2], [20, 4], [21, 8], [22, 16]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11]]+        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -261,11 +265,15 @@       "forbid_flags": ["bridge", "tunnel", "link"],       "light": "#e0e0e0",       "dark": "#111318",-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[9, 0], [9.5, 1]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[9, 0], [9.5, 1], [18, 1], [19, 2], [20, 4], [21, 8], [22, 16]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[6, 0], [12, 1.6], [15, 3], [18, 13]]+        "stops": [[6, 0], [12, 1.6], [15, 3], [18, 13], [19, 26], [20, 52], [21, 104], [22, 208]]       }     },     {@@ -280,12 +288,12 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[7, 0], [7.5, 1], [20, 15]]+        "stops": [[7, 0], [7.5, 1], [20, 15], [21, 30], [22, 60]]       },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[3, 0], [3.5, 0.5], [18, 15]]+        "stops": [[3, 0], [3.5, 0.5], [18, 15], [19, 30], [20, 60], [21, 120], [22, 240]]       }     },     {@@ -298,11 +306,15 @@       "light": "#e0e0e0",       "dark": "#111318",       "minzoom": 13,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[13, 0], [13.5, 1.5]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[13, 0], [13.5, 1.5], [18, 1.5], [19, 3], [20, 6], [21, 12], [22, 24]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[13, 0], [13.5, 1], [18, 11]]+        "stops": [[13, 0], [13.5, 1], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -316,11 +328,15 @@       "light": "#e0e0e0",       "dark": "#111318",       "minzoom": 12,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[7, 0], [7.5, 1], [20, 15]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[7, 0], [7.5, 1], [20, 15], [21, 30], [22, 60]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[3, 0], [3.5, 0.5], [18, 15]]+        "stops": [[3, 0], [3.5, 0.5], [18, 15], [19, 30], [20, 60], [21, 120], [22, 240]]       }     },     {@@ -333,11 +349,15 @@       "light": "#e0e0e0",       "dark": "#111318",       "minzoom": 12,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[9, 0], [9.5, 1.5]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[9, 0], [9.5, 1.5], [18, 1.5], [19, 3], [20, 6], [21, 12], [22, 24]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[7, 0], [7.5, 0.5], [18, 10]]+        "stops": [[7, 0], [7.5, 0.5], [18, 10], [19, 20], [20, 40], [21, 80], [22, 160]]       }     },     {@@ -350,11 +370,15 @@       "light": "#e0e0e0",       "dark": "#111318",       "minzoom": 12,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[13, 0], [13.5, 0.8]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[13, 0], [13.5, 0.8], [18, 0.8], [19, 1.6], [20, 3.2], [21, 6.4], [22, 12.8]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11]]+        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -367,11 +391,15 @@       "light": "#e0e0e0",       "dark": "#111318",       "minzoom": 12,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[12, 0], [12.5, 1.5]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[12, 0], [12.5, 1.5], [18, 1.5], [19, 3], [20, 6], [21, 12], [22, 24]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[13, 0], [13.5, 1], [18, 11]]+        "stops": [[13, 0], [13.5, 1], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -384,11 +412,15 @@       "light": "#e0e0e0",       "dark": "#111318",       "minzoom": 12,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[14, 0], [20, 7]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[14, 0], [20, 7], [21, 14], [22, 28]]+      },       "gap_width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[14, 0], [20, 7]]+        "stops": [[14, 0], [20, 7], [21, 14], [22, 28]]       }     },     {@@ -400,7 +432,11 @@       "forbid_flags": ["bridge", "tunnel"],       "light": "#ebebeb",       "dark": "#26282e",-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[14, 0], [20, 7]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[14, 0], [20, 7], [21, 14], [22, 28]]+      },       "dash": [3, 1]     },     {@@ -416,7 +452,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11]]+        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -431,7 +467,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[6, 0], [12, 1.6], [15, 3], [18, 13]]+        "stops": [[6, 0], [12, 1.6], [15, 3], [18, 13], [19, 26], [20, 52], [21, 104], [22, 208]]       }     },     {@@ -446,7 +482,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[3, 0], [6, 1.1], [12, 1.6], [15, 5], [18, 15]]+        "stops": [[3, 0], [6, 1.1], [12, 1.6], [15, 5], [18, 15], [19, 30], [20, 60], [21, 120], [22, 240]]       }     },     {@@ -461,7 +497,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[13, 0], [13.5, 1], [18, 11]]+        "stops": [[13, 0], [13.5, 1], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -477,7 +513,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[3, 0], [6, 1.1], [12, 1.6], [15, 5], [18, 15]]+        "stops": [[3, 0], [6, 1.1], [12, 1.6], [15, 5], [18, 15], [19, 30], [20, 60], [21, 120], [22, 240]]       }     },     {@@ -493,7 +529,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[6, 0], [12, 1.6], [15, 3], [18, 13]]+        "stops": [[6, 0], [12, 1.6], [15, 3], [18, 13], [19, 26], [20, 52], [21, 104], [22, 208]]       }     },     {@@ -509,7 +545,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11]]+        "stops": [[11, 0], [12.5, 0.5], [15, 2], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -525,7 +561,7 @@       "width": {         "interpolate": "exponential",         "base": 1.6,-        "stops": [[13, 0], [13.5, 1], [18, 11]]+        "stops": [[13, 0], [13.5, 1], [18, 11], [19, 22], [20, 44], [21, 88], [22, 176]]       }     },     {@@ -538,7 +574,11 @@       "light": "#ebebeb",       "dark": "#26282e",       "minzoom": 12,-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[14, 0], [20, 7]] },+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[14, 0], [20, 7], [21, 14], [22, 28]]+      },       "dash": [2, 1]     },     {@@ -551,7 +591,11 @@       "details": ["service"],       "light": "#ebebeb",       "dark": "#34383f",-      "width": { "interpolate": "exponential", "base": 1.6, "stops": [[13, 0], [18, 8]] }+      "width": {+        "interpolate": "exponential",+        "base": 1.6,+        "stops": [[13, 0], [18, 8], [19, 16], [20, 32], [21, 64], [22, 128]]+      }     },     {       "id": "roads-rail",
library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.ktindex db5f015e56..2340092091 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt@@ -41,6 +41,7 @@ import androidx.compose.material.icons.filled.TurnSharpRight import androidx.compose.material.icons.filled.TurnSlightLeft import androidx.compose.material.icons.filled.TurnSlightRight import androidx.compose.material.icons.filled.UTurnLeft+import androidx.compose.material.icons.filled.UTurnRight import androidx.compose.material.icons.filled.WbCloudy import androidx.compose.material.icons.filled.ChangeHistory import androidx.compose.material.icons.filled.ChatBubbleOutline@@ -231,6 +232,7 @@ import androidx.compose.material.icons.filled.Unarchive import androidx.compose.material.icons.filled.Upload import androidx.compose.material.icons.filled.VerifiedUser import androidx.compose.material.icons.filled.Videocam+import androidx.compose.material.icons.filled.Vaccines import androidx.compose.material.icons.filled.Visibility import androidx.compose.material.icons.filled.VisibilityOff import androidx.compose.material.icons.filled.Warning@@ -282,6 +284,7 @@ import androidx.compose.ui.graphics.vector.path import androidx.compose.ui.unit.dp import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.NavKey+import kotlin.math.sqrt  /**  * App-facing icon set. Every shared icon is rendered from `material-icons-extended`@@ -1024,6 +1027,13 @@ fun IconTurnSharpRight(modifier: Modifier = Modifier, tint: Color = LocalContent fun IconUTurn(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =     AppIcon(Icons.Filled.UTurnLeft, "U-turn", modifier, tint) +// Left and right U-turns are a real geometric distinction the router already+// draws, not an RTL mirror — an RTL locale in a right-hand-traffic country+// still turns left — so this is a separate glyph rather than AutoMirrored.+@Composable+fun IconUTurnRight(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =+    AppIcon(Icons.Filled.UTurnRight, "U-turn right", modifier, tint)+ @Composable fun IconStraight(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =     AppIcon(Icons.Filled.Straight, "Straight", modifier, tint)@@ -1069,6 +1079,13 @@ private const val LANE_STROKE_WIDTH = 2.2f /** Where the branches leave the shaft. Every branch starts here so they fan out together. */ private const val LANE_FORK_Y = 15f +/** Where the shaft stops on a through lane, leaving room for its head above. */+private const val LANE_THROUGH_TOP = 7f++// One size for every head, through and branch alike.+private const val LANE_HEAD_LENGTH = 4.6f+private const val LANE_HEAD_HALF_WIDTH = 3.1f+ private enum class LaneBranch { LEFT, SLIGHT_LEFT, RIGHT, SLIGHT_RIGHT }  private fun ImageVector.Builder.laneStroke(pathBuilder: PathBuilder.() -> Unit) =@@ -1080,21 +1097,50 @@ private fun ImageVector.Builder.laneStroke(pathBuilder: PathBuilder.() -> Unit)         pathBuilder = pathBuilder,     ) -/** Arrowhead as a filled triangle: the tip plus the two base corners. */+/**+ * Arrowhead at ([baseX], [baseY]) pointing along the unit vector+ * ([dirX], [dirY]). Every head is built from the one size pair, so the through+ * head and the branch heads cannot drift apart — an oversized through head+ * reads as "straight on is the important one" when the movements are equal.+ */ private fun ImageVector.Builder.laneHead(-    tipX: Float,-    tipY: Float,-    baseAx: Float,-    baseAy: Float,-    baseBx: Float,-    baseBy: Float,+    baseX: Float,+    baseY: Float,+    dirX: Float,+    dirY: Float, ) = path(fill = SolidColor(Color.Black)) {-    moveTo(tipX, tipY)-    lineTo(baseAx, baseAy)-    lineTo(baseBx, baseBy)+    // Base corners are the base point offset along the normal, so the head is+    // square to its own direction whatever angle the branch leaves at.+    val normalX = -dirY * LANE_HEAD_HALF_WIDTH+    val normalY = dirX * LANE_HEAD_HALF_WIDTH+    moveTo(baseX + dirX * LANE_HEAD_LENGTH, baseY + dirY * LANE_HEAD_LENGTH)+    lineTo(baseX + normalX, baseY + normalY)+    lineTo(baseX - normalX, baseY - normalY)     close() } +/**+ * One branch: a quadratic leaving the shaft at the fork for ([endX], [endY])+ * via ([controlX], [controlY]), plus its head. The head direction is the+ * curve's exit tangent — control-to-end for a quadratic — so it is aligned by+ * construction rather than by hand-solved coordinates.+ */+private fun ImageVector.Builder.laneBranch(+    controlX: Float,+    controlY: Float,+    endX: Float,+    endY: Float,+) {+    laneStroke {+        moveTo(LANE_SHAFT_X, LANE_FORK_Y)+        quadTo(controlX, controlY, endX, endY)+    }+    val runX = endX - controlX+    val runY = endY - controlY+    val length = sqrt(runX * runX + runY * runY)+    laneHead(endX, endY, runX / length, runY / length)+}+ private fun laneVector(     name: String,     through: Boolean,@@ -1111,39 +1157,15 @@ private fun laneVector(     // the fork so the branches are the only thing carrying a head.     builder.laneStroke {         moveTo(LANE_SHAFT_X, 21f)-        verticalLineTo(if (through) 7f else LANE_FORK_Y)+        verticalLineTo(if (through) LANE_THROUGH_TOP else LANE_FORK_Y)     }-    if (through) builder.laneHead(LANE_SHAFT_X, 2f, 15.2f, 7.4f, 8.8f, 7.4f)+    if (through) builder.laneHead(LANE_SHAFT_X, LANE_THROUGH_TOP, 0f, -1f)     branches.forEach { branch ->         when (branch) {-            LaneBranch.RIGHT -> {-                builder.laneStroke {-                    moveTo(LANE_SHAFT_X, LANE_FORK_Y)-                    quadTo(LANE_SHAFT_X, 9.5f, 18f, 9.5f)-                }-                builder.laneHead(22f, 9.5f, 18f, 6.5f, 18f, 12.5f)-            }-            LaneBranch.LEFT -> {-                builder.laneStroke {-                    moveTo(LANE_SHAFT_X, LANE_FORK_Y)-                    quadTo(LANE_SHAFT_X, 9.5f, 6f, 9.5f)-                }-                builder.laneHead(2f, 9.5f, 6f, 12.5f, 6f, 6.5f)-            }-            LaneBranch.SLIGHT_RIGHT -> {-                builder.laneStroke {-                    moveTo(LANE_SHAFT_X, LANE_FORK_Y)-                    quadTo(LANE_SHAFT_X, 10.5f, 16.5f, 7.5f)-                }-                builder.laneHead(20.2f, 5f, 18.2f, 10f, 14.8f, 5f)-            }-            LaneBranch.SLIGHT_LEFT -> {-                builder.laneStroke {-                    moveTo(LANE_SHAFT_X, LANE_FORK_Y)-                    quadTo(LANE_SHAFT_X, 10.5f, 7.5f, 7.5f)-                }-                builder.laneHead(3.8f, 5f, 5.8f, 10f, 9.2f, 5f)-            }+            LaneBranch.RIGHT -> builder.laneBranch(LANE_SHAFT_X, 9.5f, 18f, 9.5f)+            LaneBranch.LEFT -> builder.laneBranch(LANE_SHAFT_X, 9.5f, 6f, 9.5f)+            LaneBranch.SLIGHT_RIGHT -> builder.laneBranch(LANE_SHAFT_X, 10.5f, 16.5f, 7.5f)+            LaneBranch.SLIGHT_LEFT -> builder.laneBranch(LANE_SHAFT_X, 10.5f, 7.5f, 7.5f)         }     }     return builder.build()@@ -1540,6 +1562,11 @@ fun IconShield(modifier: Modifier = Modifier, tint: Color = LocalContentColor.cu fun IconMedication(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =     AppIcon(Icons.Filled.Medication, "Medication", modifier, tint) +/** Syringe — immunisations and the vaccination log. */+@Composable+fun IconVaccine(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =+    AppIcon(Icons.Filled.Vaccines, "Vaccine", modifier, tint)+ /** Heart on a monitor trace — medical records and vitals. */ @Composable fun IconMonitorHeart(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =
maps/src/main/java/com/vayunmathur/maps/ui/ManeuverIcon.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/ManeuverIcon.kt b/maps/src/main/java/com/vayunmathur/maps/ui/ManeuverIcon.ktindex 90ec616ee0..9d812e981c 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/ManeuverIcon.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/ManeuverIcon.kt@@ -20,6 +20,7 @@ import com.vayunmathur.library.ui.IconTurnSharpRight import com.vayunmathur.library.ui.IconTurnSlightLeft import com.vayunmathur.library.ui.IconTurnSlightRight import com.vayunmathur.library.ui.IconUTurn+import com.vayunmathur.library.ui.IconUTurnRight import com.vayunmathur.maps.R import com.vayunmathur.maps.util.RouteService.API.Maneuver @@ -31,7 +32,7 @@ fun Maneuver.iconContent(): (@Composable (Modifier, Color) -> Unit)? = when (thi     Maneuver.TURN_LEFT -> { m, t -> IconTurnLeft(m, t) }     Maneuver.TURN_SLIGHT_RIGHT -> { m, t -> IconTurnSlightRight(m, t) }     Maneuver.TURN_SHARP_RIGHT -> { m, t -> IconTurnSharpRight(m, t) }-    Maneuver.UTURN_RIGHT -> { m, t -> IconUTurn(m, t) }+    Maneuver.UTURN_RIGHT -> { m, t -> IconUTurnRight(m, t) }     Maneuver.TURN_RIGHT -> { m, t -> IconTurnRight(m, t) }     Maneuver.STRAIGHT -> { m, t -> IconStraight(m, t) }     Maneuver.RAMP_LEFT -> { m, t -> IconRampLeft(m, t) }
maps/src/test/java/com/vayunmathur/maps/ui/MapScaleBarTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/MapScaleBarTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/MapScaleBarTest.ktnew file mode 100644index 0000000000..8b403c6e35--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/MapScaleBarTest.kt@@ -0,0 +1,103 @@+package com.vayunmathur.maps.ui++import kotlin.math.abs+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * The scale bar previously overstated ground distance by a factor of six, which was two+ * independent errors multiplied together:+ *+ *  - it used 156543.03392, the z0 ground resolution for a **256**-px tile, while this stack is+ *    a 512-dp tile grid everywhere else (`Mercator.TILE_SIZE`, the Rust camera's `TILE_SIZE`) —+ *    a factor of 2; and+ *  - it then treated that per-**dp** figure as if it were per-**device pixel**, measuring the+ *    bar budget with `96.dp.toPx()` and laying the bar out in device px — a factor of the screen+ *    density, 3.0 on the device this was caught on.+ *+ * Both errors were in the same direction and the bar was internally self-consistent (label and+ * width derived from the same wrong number), so it looked plausible on screen and was only+ * wrong against the map underneath it. `cos(latitude)` was present and correct throughout.+ *+ * These assertions pin the ground truth independently of the implementation's algebra: the+ * world is 40075016.686 m around and 512 dp wide at z0, and latitude shrinks it by `cos φ`.+ */+class MapScaleBarTest {++    private fun assertClose(expected: Double, actual: Double, relativeTolerance: Double = 1e-9) {+        assertTrue(+            abs(actual - expected) <= abs(expected) * relativeTolerance,+            "expected $actual to be within ${relativeTolerance * 100}% of $expected",+        )+    }++    @Test+    fun `the world is 512 dp wide at zoom zero`() {+        assertClose(40075016.686, metersPerDp(zoom = 0.0, latitude = 0.0) * 512.0)+    }++    @Test+    fun `ground resolution halves with every zoom level`() {+        val z10 = metersPerDp(zoom = 10.0, latitude = 51.5)+        assertClose(z10 / 2.0, metersPerDp(zoom = 11.0, latitude = 51.5))+        assertClose(z10 / 1024.0, metersPerDp(zoom = 20.0, latitude = 51.5))+    }++    @Test+    fun `latitude shrinks ground resolution by cos of the parallel`() {+        val equator = metersPerDp(zoom = 14.0, latitude = 0.0)+        // cos 60 is exactly 0.5, so this catches a missing, doubled or squared cos term.+        assertClose(equator * 0.5, metersPerDp(zoom = 14.0, latitude = 60.0), 1e-6)+        assertClose(equator, metersPerDp(zoom = 14.0, latitude = -0.0))+        // Symmetric about the equator.+        assertClose(+            metersPerDp(zoom = 14.0, latitude = 37.58),+            metersPerDp(zoom = 14.0, latitude = -37.58),+        )+    }++    @Test+    fun `ground resolution matches the field-calibrated Broadway screenshot`() {+        // analysis/device_lanes2.png: z 17.8, lat 37.58, calibrated at 0.272 m per dp from the+        // lane-divider pitch. The old code reported 0.544 (x2) and laid it out against device+        // pixels (x3), for 118 px labelled "200 ft" where the ground truth was ~15 m.+        assertClose(0.27181, metersPerDp(zoom = 17.8, latitude = 37.58), 0.01)+    }++    @Test+    fun `the labelled distance is a nice round number that fits the bar`() {+        val (metres, metresLabel) = scaleBar(maxMeters = 26.1, imperial = false)+        assertEquals("20 m", metresLabel)+        assertClose(20.0, metres)++        val (kilometres, kilometresLabel) = scaleBar(maxMeters = 4900.0, imperial = false)+        assertEquals("2 km", kilometresLabel)+        assertClose(2000.0, kilometres)++        val (feet, feetLabel) = scaleBar(maxMeters = 26.1, imperial = true)+        assertEquals("50 ft", feetLabel)+        assertClose(50.0 / 3.28084, feet)++        val (miles, milesLabel) = scaleBar(maxMeters = 4900.0, imperial = true)+        assertEquals("2 mi", milesLabel)+        assertClose(2.0 * 1609.34, miles)+    }++    @Test+    fun `the bar never draws wider than its dp budget`() {+        for (zoom in 0..22) {+            for (latitude in listOf(-85.0, -37.58, 0.0, 37.58, 60.0, 85.0)) {+                val metersPerDp = metersPerDp(zoom.toDouble(), latitude)+                for (imperial in listOf(false, true)) {+                    val (barMeters, label) = scaleBar(metersPerDp * MAX_BAR_DP, imperial)+                    val widthDp = barMeters / metersPerDp+                    assertTrue(+                        widthDp in 0.0..MAX_BAR_DP,+                        "z$zoom lat$latitude \"$label\" wants $widthDp dp of $MAX_BAR_DP",+                    )+                }+            }+        }+    }+}