map: globe scale blend, antimeridian wrap, label dedup and pick fixes
- Commit
596ec823ef3c342377d22586495ec2764646f229- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-26 19:46 UTC (1 month ago)
- Parents
109b234
Diff
library/map/src/main/java/com/vayunmathur/library/map/CameraState.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/CameraState.kt b/library/map/src/main/java/com/vayunmathur/library/map/CameraState.ktindex fec9dfc812..929b891bd6 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/CameraState.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/CameraState.kt@@ -162,11 +162,14 @@ class CameraState(initial: CameraPosition = CameraPosition()) { // The short way round, so a turn from 350 to 10 degrees goes through north rather // than the long way through south. Inert on the phone, where both ends are zero. val turn = angleDelta(start.bearing, target.bearing)+ // Longitude likewise: a flight from 179 E to 179 W hops the antimeridian rather than+ // sweeping across the whole planet.+ val lonStep = angleDelta(start.target.longitude, target.target.longitude) Animatable(0f).animateTo(1f, tween(durationMs)) { val t = value.toDouble() position = CameraPosition( target = GeoPoint(- lerp(start.target.longitude, target.target.longitude, t),+ wrapLongitude(start.target.longitude + lonStep * t), lerp(start.target.latitude, target.target.latitude, t), ), zoom = lerp(start.zoom, target.zoom, t),@@ -354,17 +357,17 @@ class CameraState(initial: CameraPosition = CameraPosition()) { * as seen through a viewport [vp]: dragging content right moves the planet * right, so the centre moves the opposite way along its own parallel/meridian. *- * The globe radius in Dp is half the world width at [zoom] (mirroring- * `globe_radius` on the native side), so one Dp is `180 / r` degrees of- * great-circle at the centre. Longitude wraps; latitude clamps to the Mercator- * bound the flat path honours. Unused [vp]: kept so the signature matches the- * flat pan it replaces at the call site.+ * One Dp at the centre is `1 / r` radians of great circle, with `r` the globe radius+ * ([globeRadius], mirroring the native `globe_radius`); a longitude step is that over+ * `cos(lat)`. Longitude wraps; latitude clamps to the Mercator bound the flat path honours.+ * Unused [vp]: kept so the signature matches the flat pan it replaces at the call site. */ internal fun globePanBy(center: GeoPoint, panDp: Offset, vp: Size, zoom: Double): GeoPoint {- val r = Mercator.worldSize(zoom) / 2.0+ val r = globeRadius(zoom, center.latitude) if (r <= 0.0) return center- val degPerDp = 180.0 / r- val lon = wrapLongitude(center.longitude - panDp.x * degPerDp)+ val degPerDp = Math.toDegrees(1.0 / r)+ val lonScale = 1.0 / cos(Math.toRadians(center.latitude)).coerceAtLeast(0.05)+ val lon = wrapLongitude(center.longitude - panDp.x * degPerDp * lonScale) val lat = (center.latitude + panDp.y * degPerDp).coerceIn(-MAX_GLOBE_LAT, MAX_GLOBE_LAT) return GeoPoint(lon, lat) }@@ -434,11 +437,14 @@ private fun CameraState.anchoredZoom( // projection of `geo` at the new zoom lands back on the anchor. val moved = globeNext.screenLocationFromPosition(geo) val want = DpOffset(anchorDp.x.dp, anchorDp.y.dp)- // Screen delta (Dp) back to a centre shift: invert through the globe- // radius scale rather than re-projecting.- val r = Mercator.worldSize(newZoom) / 2.0- val dLon = (want.x.value - moved.x.value) / r * 180.0- val dLat = -(want.y.value - moved.y.value) / r * 180.0+ // Screen delta (Dp) back to a centre shift, through the sphere's centre scale:+ // `globeNext` is centred on `geo`, so `moved` is the viewport centre, and putting+ // `geo` at `want` means moving the centre the *opposite* way by the offset. A Dp is+ // `1 / r` radians of latitude and `1 / (r cos lat)` of longitude; screen y is down.+ val r = globeRadius(newZoom, geo.latitude)+ val cosLat = cos(Math.toRadians(geo.latitude)).coerceAtLeast(0.05)+ val dLon = -Math.toDegrees((want.x.value - moved.x.value) / (r * cosLat))+ val dLat = Math.toDegrees((want.y.value - moved.y.value) / r) return from.copy( target = GeoPoint( wrapLongitude(geo.longitude + dLon),
library/map/src/main/java/com/vayunmathur/library/map/Projection.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/Projection.kt b/library/map/src/main/java/com/vayunmathur/library/map/Projection.ktindex 9b9c30bce3..42550aad09 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/Projection.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/Projection.kt@@ -225,14 +225,8 @@ class Projection internal constructor( return GeoPoint(lon, lat) } - /** Screen radius of the globe in Dp: the sphere that fits the zoom scale. */- private fun globeRadius(): Double {- // World width at this zoom is `worldSize`; the globe shows half the planet- // across 2r, so r = worldSize/2 scaled to the viewport: match the native- // `globe_radius` (screen-fit radius at the same zoom).- val world = Mercator.worldSize(zoom)- return world / 2.0- }+ /** Screen radius of the globe in Dp: see the top-level [globeRadius]. */+ private fun globeRadius(): Double = globeRadius(zoom, center.latitude) /** * Visible-ground bounds on the globe: the hemisphere cap around the centre,@@ -345,6 +339,22 @@ class Projection internal constructor( */ const val GLOBE_DETAIL_ZOOM = 8.0 +/** Zoom at which [globeRadius] starts blending toward the flat scale. Mirrors the native `GLOBE_BLEND_START`. */+const val GLOBE_BLEND_START_ZOOM = 5.0++/**+ * Screen radius of the globe in Dp at [zoom], centred on [centerLatitude]. Mirrors the native+ * `globe_radius`: half the world width when zoomed out, blending geometrically to the flat+ * Mercator centre scale (`world / (2 * PI * cos(lat))`) by [GLOBE_DETAIL_ZOOM], so the switch+ * to the flat map does not jump.+ */+fun globeRadius(zoom: Double, centerLatitude: Double): Double {+ val t = ((zoom - GLOBE_BLEND_START_ZOOM) / (GLOBE_DETAIL_ZOOM - GLOBE_BLEND_START_ZOOM)).coerceIn(0.0, 1.0)+ val c = cos(Math.toRadians(centerLatitude)).coerceAtLeast(0.05)+ val toFlat = 1.0 / (PI * c)+ return Mercator.worldSize(zoom) / 2.0 * Math.pow(toFlat, t)+}+ /** Half the full circle: antimeridian wrap threshold. */ private const val ANTIMERIDIAN_SPAN_DEG = 180.0
library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt b/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.ktindex 57de98d0c3..cfeb93a745 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt@@ -636,15 +636,19 @@ class SurfaceMapRenderer( requestFrame() return }- if (System.nanoTime() - lastChangeNanos < IDLE_GRACE_NANOS || !regionResolved) {+ if (System.nanoTime() - lastChangeNanos < IDLE_GRACE_NANOS) { requestFrame() return } // Nothing local is changing, so the native side decides: draw now, draw later, or stop.+ // An unresolved region mask retries once its tiles land, which is a frame the native+ // side already asks for; with nothing pending (offline, say) it polls on a slow cadence+ // rather than spinning the loop at 60 fps. val delay = MapNative.nextFrameDelayMillis(handle) when { delay == 0L -> requestFrame()- delay > 0L -> requestFrameDelayed(delay)+ delay > 0L -> requestFrameDelayed(if (regionResolved) delay else minOf(delay, REGION_RETRY_MILLIS))+ !regionResolved -> requestFrameDelayed(REGION_RETRY_MILLIS) } } @@ -769,7 +773,8 @@ class SurfaceMapRenderer( // `0` clears above; a nonzero id returns nonzero once a resident tile carries it. // `0` back means the tiles have not landed yet — retried next frame, not a miss. val resolved = MapNative.setRegionMask(handle, id) != 0L- Log.dev("RegionDbg", "applyRegionMask id=$id resolved=$resolved")+ // Logged on the transition only: this runs every retry frame while unresolved.+ if (resolved) Log.dev("RegionDbg", "applyRegionMask id=$id resolved") regionResolved = resolved } @@ -881,6 +886,9 @@ data class MoonTextures( */ internal val IDLE_GRACE_NANOS = java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(250) + /** Retry cadence for an unresolved region mask while no tile work is pending. */+ const val REGION_RETRY_MILLIS = 500L+ // DEFAULT_ROUTE_COLOR lives in SurfaceMapOverlays.kt. } }
library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt b/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.ktindex 1f0e0ae284..3dc689fbf1 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt@@ -9,7 +9,10 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.key import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext@@ -122,8 +125,19 @@ internal fun VulkanMapSurface( ) { val context = LocalContext.current val density = LocalDensity.current.density- val host = remember(context, tileSource) { MapSurfaceHost(context, cameraState, density, tileSource, onFrame) }+ // The host is rebuilt on a density change (the renderer's Dp<->px scale is fixed per+ // instance), and reads `onFrame` through the latest-value holder so a new lambda is honoured.+ val currentOnFrame by rememberUpdatedState(onFrame)+ val host = remember(context, tileSource, density) {+ MapSurfaceHost(context, cameraState, density, tileSource) { currentOnFrame() }+ } val renderer = host.renderer+ // The renderer pulls its camera from here every frame; a new CameraState must replace the+ // one the host was built with, or the map keeps drawing the old camera.+ LaunchedEffect(host, cameraState) {+ renderer.composeCamera = cameraState+ renderer.invalidate()+ } // Task-17 pick wiring: the projection answers queryRenderedLabels from // the native placed-label snapshot owned by this surface's renderer.@@ -230,6 +244,9 @@ internal fun VulkanMapSurface( if (active) { active = false renderer.setGestureActive(false, 0f)+ // Wake the loop: if the idle grace already lapsed, nothing else would draw+ // the frame that lets the native side settle and fetch the final zoom.+ renderer.invalidate() } continue }@@ -330,17 +347,21 @@ internal fun VulkanMapSurface( } Box(modifier) {- AndroidView(- factory = {- TextureView(context).apply {- // The map is opaque, so tell the compositor: a translucent TextureView is- // blended every frame for nothing.- isOpaque = true- surfaceTextureListener = host- }- },- modifier = Modifier.fillMaxSize(),- )+ // Keyed on the host: a rebuilt host (tile source or density change) needs a fresh+ // TextureView, because the old view's listener and surface belong to the old host.+ key(host) {+ AndroidView(+ factory = {+ TextureView(context).apply {+ // The map is opaque, so tell the compositor: a translucent TextureView is+ // blended every frame for nothing.+ isOpaque = true+ surfaceTextureListener = host+ }+ },+ modifier = Modifier.fillMaxSize(),+ )+ } // The debug table floats over the surface's top-start corner; gated inside, so // `false` composes nothing at all.
library/map/src/main/rust/shaders/line_globe.vert
diff --git a/library/map/src/main/rust/shaders/line_globe.vert b/library/map/src/main/rust/shaders/line_globe.vertindex 62663eceee..10920f85e2 100644--- a/library/map/src/main/rust/shaders/line_globe.vert+++ b/library/map/src/main/rust/shaders/line_globe.vert@@ -36,12 +36,14 @@ void main() { float ox = push.tileToClip[0][2]; float oy = push.tileToClip[1][2]; float span = push.tileToClip[2][2];- // `misc.x` is the flat tile's px span. On the ball (radius = half the flat world width)- // Mercator's conformal scale makes one tile unit pi * cos(lat) times longer, in both- // directions, so widths and dash lengths convert through the globe's own span.- // cos(lat) = 1 / cosh(n) for the Mercator n of this vertex's unbent position.+ // `misc.x` is the flat tile's px span (span * world). On the ball one tile unit spans+ // 2 * pi * r * cos(lat) * span Dp in both directions (Mercator is conformal), so widths+ // and dash lengths convert through that span instead. `world` (Dp) rides in the globe+ // matrix's m[14]; cos(lat) = 1 / cosh(n) for the Mercator n of the unbent position. float n0 = PI - 2.0 * PI * (oy + inPosition.y * span);- float tilePx = max(push.misc.x, 1.0) * PI * max(1.0 / cosh(n0), 0.05);+ float worldDp = max(push.tileToClip[3][2], 1e-6);+ float tilePx = max(push.misc.x, 1.0)+ * (2.0 * PI * push.morph.z * max(1.0 / cosh(n0), 0.05) / worldDp); float wantHalfPx = push.line.x; float gapHalfPx = push.line.y; float lateralPx = push.misc.z;
library/map/src/main/rust/shaders/road_surface_globe.vert
diff --git a/library/map/src/main/rust/shaders/road_surface_globe.vert b/library/map/src/main/rust/shaders/road_surface_globe.vertindex 585fe91813..031666484a 100644--- a/library/map/src/main/rust/shaders/road_surface_globe.vert+++ b/library/map/src/main/rust/shaders/road_surface_globe.vert@@ -34,7 +34,9 @@ void main() { float span = push.tileToClip[2][2]; // The globe's own px per tile unit: see `line_globe.vert`. float n0 = PI - 2.0 * PI * (oy + inPosition.y * span);- float tilePx = max(push.misc.x, 1.0) * PI * max(1.0 / cosh(n0), 0.05);+ float worldDp = max(push.tileToClip[3][2], 1e-6);+ float tilePx = max(push.misc.x, 1.0)+ * (2.0 * PI * push.morph.z * max(1.0 / cosh(n0), 0.05) / worldDp); float wantHalfPx = push.line.x; float halfWidthPx = max(wantHalfPx, MIN_HALF_WIDTH_PX); vec2 offsetTile = inNormal * (inT * halfWidthPx / tilePx);
library/map/src/main/rust/shaders/symbol_globe.vert
diff --git a/library/map/src/main/rust/shaders/symbol_globe.vert b/library/map/src/main/rust/shaders/symbol_globe.vertindex af74104eaa..6e17c13dbd 100644--- a/library/map/src/main/rust/shaders/symbol_globe.vert+++ b/library/map/src/main/rust/shaders/symbol_globe.vert@@ -63,13 +63,13 @@ void main() { float hw = push.morph.x; float hh = push.morph.y; // Screen offset of this corner from its anchor. Labels are shaped in flat tile-local- // units, where one unit is `tile_span_dp = span * world_size = span * 2r` Dp; the globe- // 2x2 is `k * r`, so the delta is scaled by `2 * span` to keep the flat screen size.+ // units, where one unit is `span * world` Dp (`world` rides in m[14]); the globe 2x2 is+ // `k * r`, so the delta is scaled by `span * world / r` to keep the flat screen size. float m00 = push.tileToClip[0][0]; float m01 = push.tileToClip[0][1]; float m10 = push.tileToClip[1][0]; float m11 = push.tileToClip[1][1];- vec2 dTile = (inPosition - inAnchor) * (2.0 * span);+ vec2 dTile = (inPosition - inAnchor) * (span * push.tileToClip[3][2] / max(r, 1e-6)); vec2 off = vec2(m00 * dTile.x + m10 * dTile.y, m01 * dTile.x + m11 * dTile.y); float ax = kx * (a.x * r) + (kx * hw - 1.0); float ay = -(ky * (a.y * r)) + (ky * hh - 1.0);
library/map/src/main/rust/src/camera.rs
diff --git a/library/map/src/main/rust/src/camera.rs b/library/map/src/main/rust/src/camera.rsindex fe5305d986..fb8bbdcdf0 100644--- a/library/map/src/main/rust/src/camera.rs+++ b/library/map/src/main/rust/src/camera.rs@@ -156,11 +156,22 @@ pub fn unproject(x: f64, y: f64, zoom: f64) -> (f64, f64) { /// in step with the Kotlin `GLOBE_DETAIL_ZOOM`. pub const GLOBE_FLAT_THRESHOLD: f64 = 8.0; -/// Screen radius of the globe in Dp: half the world width at this zoom, so the-/// sphere shows half the planet across its diameter. Mirrors the Kotlin-/// `Projection.globeRadius`.-pub fn globe_radius(zoom: f64) -> f64 {- world_size(zoom) / 2.0+/// Zoom at which [`globe_radius`] starts blending from the half-world sphere toward the flat+/// map's scale. Must stay in step with the Kotlin `GLOBE_BLEND_START_ZOOM`.+pub const GLOBE_BLEND_START: f64 = 5.0;++/// Screen radius of the globe in Dp, for a camera at `zoom` centred on `center_lat`.+///+/// Zoomed out (below [`GLOBE_BLEND_START`]) it is half the world width, so the sphere shows+/// half the planet across its diameter and fills the screen. By [`GLOBE_FLAT_THRESHOLD`] it+/// must match the flat Mercator scale at the centre — `world / (2 * pi * cos(lat))` — or the+/// switch to the flat map jumps about 1.65 zoom levels. Between the two the factor blends+/// geometrically. Mirrors the Kotlin `globeRadius`.+pub fn globe_radius(zoom: f64, center_lat: f64) -> f64 {+ let t = ((zoom - GLOBE_BLEND_START) / (GLOBE_FLAT_THRESHOLD - GLOBE_BLEND_START)).clamp(0.0, 1.0);+ let cos = center_lat.to_radians().cos().max(0.05);+ let to_flat = 1.0 / (std::f64::consts::PI * cos);+ world_size(zoom) / 2.0 * to_flat.powf(t) } /// Whether this camera draws the globe: the flag on, and close enough out that
library/map/src/main/rust/src/camera_extra.rs
diff --git a/library/map/src/main/rust/src/camera_extra.rs b/library/map/src/main/rust/src/camera_extra.rsindex 6a1e7a91bb..4915b5e7e1 100644--- a/library/map/src/main/rust/src/camera_extra.rs+++ b/library/map/src/main/rust/src/camera_extra.rs@@ -184,7 +184,15 @@ impl Camera { let anchor = project(lon, lat, self.zoom); let center = project(self.center_lon, self.center_lat, self.zoom); let (cos, sin) = self.rotation();- let dx = anchor.x - center.x;+ // A point is wherever its nearest copy is: a pin just across the antimeridian is a+ // few Dp east, not a world-width west.+ let size = crate::camera::world_size(self.zoom);+ let mut dx = anchor.x - center.x;+ if dx > size / 2.0 {+ dx -= size;+ } else if dx < -size / 2.0 {+ dx += size;+ } let dy = anchor.y - center.y; if self.pitch_deg == 0.0 { let kx = 2.0 / self.width_dp as f64;
library/map/src/main/rust/src/camera_globe.rs
diff --git a/library/map/src/main/rust/src/camera_globe.rs b/library/map/src/main/rust/src/camera_globe.rsindex e080953ec6..d3cf9b4d4d 100644--- a/library/map/src/main/rust/src/camera_globe.rs+++ b/library/map/src/main/rust/src/camera_globe.rs@@ -15,7 +15,8 @@ impl Camera { /// reconstruct the lon/lat per vertex. /// /// The translation column carries the camera centre lon/lat in m[12]/m[13]- /// (degrees) — the sphere basis every globe vertex shader needs. It rides+ /// (degrees) — the sphere basis every globe vertex shader needs — and the flat+ /// world width (Dp) in m[14], the scale flat tile-local sizes are measured in. It rides /// here rather than in the push block because the block is exactly at the /// guaranteed 128-byte limit: this keeps `misc`/`morph` meaning what the /// flat path means (tile px, edge AA, fade, span scale, dash speed), so the@@ -29,7 +30,7 @@ impl Camera { /// through this same matrix, so a label or POI placed CPU-side lands where /// the basemap under it drew. pub fn globe_tile_to_clip(&self, z: u8, x: u32, y: u32) -> [f32; 16] {- let r = crate::camera::globe_radius(self.zoom);+ let r = crate::camera::globe_radius(self.zoom, self.center_lat); let kx = 2.0 / self.width_dp as f64; let ky = 2.0 / self.height_dp as f64; // Tile origin/span in *normalised world* (0..1 across the planet): stable@@ -53,7 +54,9 @@ impl Camera { 0.0, // self.center_lon as f32, self.center_lat as f32,- 0.0,+ // The flat world width (Dp): what flat tile-local sizes (line widths, label quads)+ // are measured against, now that `r` is no longer a fixed fraction of it.+ crate::camera::world_size(self.zoom) as f32, 1.0, ] }@@ -66,7 +69,7 @@ impl Camera { if z < 0.0 { return None; }- let r = crate::camera::globe_radius(self.zoom);+ let r = crate::camera::globe_radius(self.zoom, self.center_lat); Some(( self.width_dp as f64 / 2.0 + x * r, self.height_dp as f64 / 2.0 - y * r,
library/map/src/main/rust/src/camera_globe_tests.rs
diff --git a/library/map/src/main/rust/src/camera_globe_tests.rs b/library/map/src/main/rust/src/camera_globe_tests.rsindex aa4702421b..f9975e3171 100644--- a/library/map/src/main/rust/src/camera_globe_tests.rs+++ b/library/map/src/main/rust/src/camera_globe_tests.rs@@ -102,9 +102,21 @@ mod tests { #[test] fn the_globe_radius_is_half_the_world() {- assert_eq!(globe_radius(0.0), 256.0);- assert_eq!(globe_radius(1.0), 512.0);- assert!((globe_radius(2.5) - 256.0 * 2f64.powf(2.5)).abs() < 1e-9);+ assert_eq!(globe_radius(0.0, 0.0), 256.0);+ assert_eq!(globe_radius(1.0, 45.0), 512.0);+ assert!((globe_radius(2.5, 0.0) - 256.0 * 2f64.powf(2.5)).abs() < 1e-9);+ }++ #[test]+ fn the_globe_meets_the_flat_scale_at_the_threshold() {+ // At the switch the sphere's centre scale (r per radian) must equal flat Mercator's+ // (world / 2pi per radian of longitude, over cos(lat)), or the map jumps.+ let z = crate::camera::GLOBE_FLAT_THRESHOLD;+ for lat in [0.0f64, 37.77, 60.0] {+ let flat = crate::camera::world_size(z) / (2.0 * std::f64::consts::PI * lat.to_radians().cos());+ let r = globe_radius(z, lat);+ assert!((r - flat).abs() / flat < 1e-9, "lat {lat}: r {r} flat {flat}");+ } } #[test]@@ -164,7 +176,7 @@ mod tests { assert_eq!(m[2], 0.0f32, "ox of tile x=0"); assert!((m[6] - (1.0 / n) as f32).abs() < 1e-9, "oy of tile y=1"); assert!((m[10] - (1.0 / n) as f32).abs() < 1e-9, "span at z2");- let r = globe_radius(2.0);+ let r = globe_radius(2.0, 37.7749); let kx = 2.0 / 512.0; assert!((m[0] as f64 - kx * r).abs() < 1e-3, "2x2 carries the globe scale"); }
library/map/src/main/rust/src/overlay.rs
diff --git a/library/map/src/main/rust/src/overlay.rs b/library/map/src/main/rust/src/overlay.rsindex 074880fc00..f87481c721 100644--- a/library/map/src/main/rust/src/overlay.rs+++ b/library/map/src/main/rust/src/overlay.rs@@ -155,6 +155,17 @@ impl RoutePlacement { ) } + /// [`at_zoom`](Self::at_zoom) at the camera's zoom, shifted to the world copy nearest the+ /// camera centre: a route crossing the antimeridian is stored unwrapped past the world edge+ /// (`overlay_parts::tessellate`), so the copy beside the camera is the one to draw.+ pub fn at_zoom_near(&self, camera: &crate::camera::Camera) -> (WorldPx, f64) {+ let (mut origin, span) = self.at_zoom(camera.zoom);+ let world = crate::camera::world_size(camera.zoom);+ let centre_x = crate::camera::project(camera.center_lon, camera.center_lat, camera.zoom).x;+ origin.x -= ((origin.x + span * 0.5 - centre_x) / world).round() * world;+ (origin, span)+ }+ /// The route line's half-width in **device px** — what a fill pass pushes. pub fn fill_half(&self, density: f32) -> f32 { self.style.width_dp * 0.5 * density
library/map/src/main/rust/src/overlay_parts.rs
diff --git a/library/map/src/main/rust/src/overlay_parts.rs b/library/map/src/main/rust/src/overlay_parts.rsindex f18247b59d..a1b265cb90 100644--- a/library/map/src/main/rust/src/overlay_parts.rs+++ b/library/map/src/main/rust/src/overlay_parts.rs@@ -22,6 +22,29 @@ use crate::tess::stroke; /// glitchy zero-length step does not blank a route being followed. A caller clearing the /// route passes an empty slice and gets `None`, which is the same thing. pub fn tessellate(segments: &[RouteSegment], style: RouteStyle) -> Option<RouteMesh> {+ // Longitudes unwrapped along the route (each point within 180 degrees of the one before,+ // runs continuing from the previous run's end), so a route crossing the antimeridian is+ // one short hop past +-180 rather than a streak back across the whole world. `project` is+ // linear in longitude, so an unwrapped point simply lands past the world edge; the draw+ // picks the world copy nearest the camera.+ let mut previous: Option<f64> = None;+ let unwrapped: Vec<Vec<(f64, f64)>> = segments+ .iter()+ .map(|segment| {+ segment+ .points+ .iter()+ .map(|&(lon, lat)| {+ let lon = match previous {+ Some(p) => p + (lon - p + 540.0).rem_euclid(360.0) - 180.0,+ None => lon,+ };+ previous = Some(lon);+ (lon, lat)+ })+ .collect()+ })+ .collect(); // The bounding box spans every run's points, so all runs normalise into the same // square and their strokes line up. Zoom 0 is the reference the mesh is stored at: // any zoom would do, since the normalisation divides the scale out, and zero needs@@ -35,8 +58,8 @@ pub fn tessellate(segments: &[RouteSegment], style: RouteStyle) -> Option<RouteM y: f64::MIN, }; let mut any = false;- for segment in segments {- for &(lon, lat) in &segment.points {+ for points in &unwrapped {+ for &(lon, lat) in points { let p = project(lon, lat, 0.0); min.x = min.x.min(p.x); min.y = min.y.min(p.y);@@ -60,13 +83,13 @@ pub fn tessellate(segments: &[RouteSegment], style: RouteStyle) -> Option<RouteM let mut indices = Vec::new(); let mut ranges = Vec::new(); let mut coords: Vec<i32> = Vec::new();- for segment in segments {- if segment.points.len() < 2 {+ for (segment, points) in segments.iter().zip(&unwrapped) {+ if points.len() < 2 { continue; } coords.clear();- coords.reserve(segment.points.len() * 2);- for &(lon, lat) in &segment.points {+ coords.reserve(points.len() * 2);+ for &(lon, lat) in points { let p = project(lon, lat, 0.0); coords.push((((p.x - min.x) / span) * EXTENT as f64).round() as i32); coords.push((((p.y - min.y) / span) * EXTENT as f64).round() as i32);
library/map/src/main/rust/src/tess/roof/geom.rs
diff --git a/library/map/src/main/rust/src/tess/roof/geom.rs b/library/map/src/main/rust/src/tess/roof/geom.rsindex ee686e1f17..cc597d1f39 100644--- a/library/map/src/main/rust/src/tess/roof/geom.rs+++ b/library/map/src/main/rust/src/tess/roof/geom.rs@@ -1,17 +1,6 @@ use super::FLOATS_PER_VERTEX; -/// The centroid of a ring's vertices (the vertex average, enough to point wall normals outward-/// for the convex-ish footprints buildings are).-pub(crate) fn ring_centroid(ring: &[(f32, f32)]) -> (f32, f32) {- let mut sx = 0.0;- let mut sy = 0.0;- for &(x, y) in ring {- sx += x;- sy += y;- }- let inv = 1.0 / ring.len() as f32;- (sx * inv, sy * inv)-}+/// The unit normal /// The unit normal of the triangle `a, b, c`, or straight up for a degenerate (zero-area) /// triangle so a sliver never emits a NaN normal.
library/map/src/main/rust/src/tess/roof/walls.rs
diff --git a/library/map/src/main/rust/src/tess/roof/walls.rs b/library/map/src/main/rust/src/tess/roof/walls.rsindex 3ea2dc430c..0e6638f453 100644--- a/library/map/src/main/rust/src/tess/roof/walls.rs+++ b/library/map/src/main/rust/src/tess/roof/walls.rs@@ -1,4 +1,4 @@-use super::geom::{push_tri, ring_centroid};+use super::geom::push_tri; /// A wall quad per footprint edge, from `base` to `wall_top`, with an outward-facing normal. ///@@ -25,9 +25,20 @@ pub(crate) fn emit_walls( if wall_top <= base { return; // A floating part flush with its base has no wall to draw. }- for ring in local {- let centroid = ring_centroid(ring);+ for (ring_index, ring) in local.iter().enumerate() { let n = ring.len();+ // Which side is outward follows from the ring's winding, not from a centroid (which can+ // sit outside an L-shaped or courtyard footprint): a positive shoelace area puts the+ // ring's interior to the left of each edge, i.e. towards (-ey, ex). The exterior ring+ // (first) faces away from its interior; a hole's walls face into the courtyard.+ let twice_area: f32 = (0..n)+ .map(|i| {+ let (x0, y0) = ring[i];+ let (x1, y1) = ring[(i + 1) % n];+ x0 * y1 - x1 * y0+ })+ .sum();+ let outward_right = (ring_index == 0) == (twice_area > 0.0); for i in 0..n { let (x0, y0) = ring[i]; let (x1, y1) = ring[(i + 1) % n];@@ -35,16 +46,8 @@ pub(crate) fn emit_walls( if ex == 0.0 && ey == 0.0 { continue; }- // The edge's two horizontal normals are (ey, -ex) and (-ey, ex). Pick the one that- // points away from the ring centroid so faces are lit as if from outside — cull is off- // in the pipeline, so this only decides shading, never visibility.- let (mx, my) = ((x0 + x1) * 0.5, (y0 + y1) * 0.5);- let mut nx = ey;- let mut ny = -ex;- if nx * (mx - centroid.0) + ny * (my - centroid.1) < 0.0 {- nx = -nx;- ny = -ny;- }+ // Cull is off in the pipeline, so this only decides shading, never visibility.+ let (nx, ny) = if outward_right { (ey, -ex) } else { (-ey, ex) }; let inv = 1.0 / (nx * nx + ny * ny).sqrt(); let normal = [nx * inv, ny * inv, 0.0];
library/map/src/main/rust/src/tile/geometry/build.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/build.rs b/library/map/src/main/rust/src/tile/geometry/build.rsindex 0dd36d87d1..cdd6afab27 100644--- a/library/map/src/main/rust/src/tile/geometry/build.rs+++ b/library/map/src/main/rust/src/tile/geometry/build.rs@@ -388,27 +388,12 @@ pub fn build_toggled( // Globe zooms: the globe shaders bend only vertices, so long edges must be split or // they cut chords through the ball. Before draping, so new vertices get their own height.- if z <= crate::camera::GLOBE_FLAT_THRESHOLD as u8 {- let max_edge = subdivide::globe_max_edge(z);- match layer.kind {- LayerKind::Fill => subdivide::subdivide(- &mut vertices,- &mut indices,- fill::FLOATS_PER_VERTEX,- max_edge,- ),- LayerKind::Line => {- subdivide::subdivide(- &mut vertices,- &mut indices,- stroke::FLOATS_PER_VERTEX,- max_edge,- );- for (_, v, i) in coloured.iter_mut() {- subdivide::subdivide(v, i, stroke::FLOATS_PER_VERTEX, max_edge);- }- }- LayerKind::Symbol => {}+ if z <= crate::camera::GLOBE_FLAT_THRESHOLD as u8 && layer.kind != LayerKind::Symbol {+ let edge = subdivide::globe_max_edge(z);+ let fpv = if layer.kind == LayerKind::Fill { fill::FLOATS_PER_VERTEX } else { stroke::FLOATS_PER_VERTEX };+ subdivide::subdivide(&mut vertices, &mut indices, fpv, edge);+ for (_, v, i) in coloured.iter_mut() {+ subdivide::subdivide(v, i, stroke::FLOATS_PER_VERTEX, edge); } } // Drape the layer's flat geometry onto the relief where the tile carries a
library/map/src/main/rust/src/vulkan/pick/pass.rs
diff --git a/library/map/src/main/rust/src/vulkan/pick/pass.rs b/library/map/src/main/rust/src/vulkan/pick/pass.rsindex a41e8967ca..322703afb0 100644--- a/library/map/src/main/rust/src/vulkan/pick/pass.rs+++ b/library/map/src/main/rust/src/vulkan/pick/pass.rs@@ -244,7 +244,22 @@ impl Pick { None => continue, } } else {- camera.screen_quad_to_clip(marker.lon, marker.lat, (MARKER_SIZE_DP * 0.5) as f64)+ let mut m =+ camera.screen_quad_to_clip(marker.lon, marker.lat, (MARKER_SIZE_DP * 0.5) as f64);+ // Behind the eye under tilt: the draw culls this pin, so the pick must too.+ if m[15] <= 0.0 {+ continue;+ }+ // The drawn icon is counter-rotated to stay screen-upright (`upright_offset`);+ // turn the tap box's axes the same way so the two cover the same pixels.+ let (cos, sin) = camera.rotation();+ let (cos, sin) = (cos as f32, sin as f32);+ let (x0, x1, y0, y1) = (m[0], m[1], m[4], m[5]);+ m[0] = cos * x0 + sin * y0;+ m[1] = cos * x1 + sin * y1;+ m[4] = -sin * x0 + cos * y0;+ m[5] = -sin * x1 + cos * y1;+ m }; let mut push = Push { tile_to_clip: matrix,
library/map/src/main/rust/src/vulkan/pick/pipeline.rs
diff --git a/library/map/src/main/rust/src/vulkan/pick/pipeline.rs b/library/map/src/main/rust/src/vulkan/pick/pipeline.rsindex 371b49eb12..97e847b741 100644--- a/library/map/src/main/rust/src/vulkan/pick/pipeline.rs+++ b/library/map/src/main/rust/src/vulkan/pick/pipeline.rs@@ -32,10 +32,11 @@ pub(super) unsafe fn build_pipeline( .name(entry), ]; - // The shared unit quad: two floats per vertex.+ // The shared unit quad (`quad::QUAD_VERTICES`): three floats per vertex, of which the+ // shader reads the first two. let binding = vk::VertexInputBindingDescription::default() .binding(0)- .stride(2 * std::mem::size_of::<f32>() as u32)+ .stride(3 * std::mem::size_of::<f32>() as u32) .input_rate(vk::VertexInputRate::VERTEX); let attribute = vk::VertexInputAttributeDescription::default() .location(0)
library/map/src/main/rust/src/vulkan/renderer/frame.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/frame.rs b/library/map/src/main/rust/src/vulkan/renderer/frame.rsindex df4b0af7b4..4542e8d06f 100644--- a/library/map/src/main/rust/src/vulkan/renderer/frame.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/frame.rs@@ -271,7 +271,7 @@ impl Renderer { // draws nothing but the clear colour — the frame still presents, so the // globe reads as empty space rather than freezing the loop. if crate::camera::moon_active(camera) {- return self.render_moon(camera);+ return self.render_moon(camera, clear); } // MapLibre-style submit early-out: when nothing changed since the last submitted
library/map/src/main/rust/src/vulkan/renderer/placement.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/placement.rs b/library/map/src/main/rust/src/vulkan/renderer/placement.rsindex 90fee58e99..aae61b1cb4 100644--- a/library/map/src/main/rust/src/vulkan/renderer/placement.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/placement.rs@@ -48,7 +48,7 @@ impl Renderer { /// of every drawing symbol layer, placed once, globally. /// /// Collision padding widens with zoom-out (see- /// [`collision_padding_px`]): at low zoom boxes overlap eagerly so only+ /// [`collision_padding_dp`]): at low zoom boxes overlap eagerly so only /// the most important places survive, matching MapLibre's ~10 cities at /// z6; at street zoom padding relaxes toward the drawn box. pub(super) fn place_symbols(@@ -260,20 +260,31 @@ impl Renderer { // bit-identical footprints for one label. The placer would accept the first // and reject the second on collision — keeping both doubles the quadratic // loop's work for nothing. Drop exact duplicates by stable feature identity- // (feature id + layer), keeping the first occurrence. Labels with no feature- // id (ID_NONE) are never deduped: they carry no identity to compare.+ // (feature id + layer). Within a layer candidates run coarsest tile first, so the+ // *last* copy is the finest tile's: keep that one, or a zoom-in keeps drawing the+ // stand-in ancestor's coarser label beside the sharpening geometry. Labels with no+ // feature id (ID_NONE) are never deduped: they carry no identity to compare. // // `candidate_id` is untouched: it still names the same label in the // accept-set `record_symbol` filters by. { let mut seen: HashSet<(u64, usize)> = HashSet::with_capacity(candidates.len());- candidates.retain(|c| {- let (feature_id, layer_index) = (c.feature_id, c.layer_index);- // Identity unknown: keep, never dedup.- if feature_id == tilecodec::mamaps::body::ID_NONE {- return true;+ let keep: Vec<bool> = {+ let mut keep = vec![true; candidates.len()];+ for (i, c) in candidates.iter().enumerate().rev() {+ // Identity unknown: keep, never dedup.+ if c.feature_id != tilecodec::mamaps::body::ID_NONE+ && !seen.insert((c.feature_id, c.layer_index))+ {+ keep[i] = false;+ } }- seen.insert((feature_id, layer_index))+ keep+ };+ let mut at = 0;+ candidates.retain(|_| {+ at += 1;+ keep[at - 1] }); } // Keyed by candidate id, valued by the anchor the placer settled on and **where in
library/map/src/main/rust/src/vulkan/renderer/placement_reuse.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/placement_reuse.rs b/library/map/src/main/rust/src/vulkan/renderer/placement_reuse.rsindex 38a85caff1..ee543c8beb 100644--- a/library/map/src/main/rust/src/vulkan/renderer/placement_reuse.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/placement_reuse.rs@@ -214,18 +214,19 @@ pub(super) fn box_inputs_with_arms( icon_px: label .sprite .map(|s| (s.width_dp * camera.density, s.height_dp * camera.density)),- pad_px: collision_padding_px(camera.zoom),+ pad_px: collision_padding_dp(camera.zoom) * camera.density, } } -/// Collision padding in device px around every label box, by camera zoom.+/// Collision padding in Dp around every label box, by camera zoom (the caller converts to+/// device px alongside the text and icon sizes). /// /// MapLibre pads every label (icon + text padding, growing at low zoom via /// the icon-padding ramp), which is what holds z6 to ~10 cities while z14 /// stays dense. Without it tight advance boxes let hundreds of villages /// survive at z6. 24px at z6 and below culls hamlets against towns; 4px at /// z14+ keeps street labels tight. Linear between.-fn collision_padding_px(zoom: f64) -> f32 {+fn collision_padding_dp(zoom: f64) -> f32 { if zoom <= 6.0 { 24.0 } else if zoom >= 14.0 {
library/map/src/main/rust/src/vulkan/renderer/record.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record.rs b/library/map/src/main/rust/src/vulkan/renderer/record.rsindex 40e626728f..8a96f002f6 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record.rs@@ -440,7 +440,7 @@ impl Renderer { // On the globe it is the globe radius (Dp) instead, and morph.xy // the half-viewport (Dp) — see the `*_globe.vert` headers. morph: if globe {- let r = crate::camera::globe_radius(camera.zoom) as f32;+ let r = crate::camera::globe_radius(camera.zoom, camera.center_lat) as f32; [ tile_fade, camera.width_dp / 2.0,
library/map/src/main/rust/src/vulkan/renderer/record_extra.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_extra.rs b/library/map/src/main/rust/src/vulkan/renderer/record_extra.rsindex 47e55c20d1..f32c316aaf 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_extra.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_extra.rs@@ -154,7 +154,7 @@ impl Renderer { // mirroring the flat layer loop. On the globe it is the globe radius // (Dp) instead, and morph.xy the half-viewport (Dp). morph: if globe {- let r = crate::camera::globe_radius(camera.zoom) as f32;+ let r = crate::camera::globe_radius(camera.zoom, camera.center_lat) as f32; [MORPH_NONE[0], camera.width_dp / 2.0, r, camera.height_dp / 2.0] } else { [MORPH_NONE[0], 0.0, camera.tile_span_dp(tile.z) as f32, 0.0]
library/map/src/main/rust/src/vulkan/renderer/record_extra2.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_extra2.rs b/library/map/src/main/rust/src/vulkan/renderer/record_extra2.rsindex 05899113d1..dbd94805bb 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_extra2.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_extra2.rs@@ -106,7 +106,7 @@ impl Renderer { let (misc, morph) = ( [tile_span_px, edge_aa, 0.0, camera.time_seconds], if globe {- let r = crate::camera::globe_radius(camera.zoom) as f32;+ let r = crate::camera::globe_radius(camera.zoom, camera.center_lat) as f32; [1.0, camera.width_dp / 2.0, r, camera.height_dp / 2.0] } else { [1.0, 0.0, camera.tile_span_dp(tile.z) as f32, 0.0]@@ -303,7 +303,7 @@ impl Renderer { binds: &mut BindState, ) { let device = &renderer.context.device;- let (origin, span) = route.placement.at_zoom(camera.zoom);+ let (origin, span) = route.placement.at_zoom_near(camera); let matrix = camera.world_quad_to_clip(origin, span); // What `line.vert` divides a pixel offset by to reach local units. The route's // square stands in for a tile here, which is the whole reason the two share a@@ -448,9 +448,7 @@ impl Renderer { let device = &self.context.device; let density = camera.density; let puck_matrix = if globe {- // `globe_anchor_to_screen` returns `None` far-side, but the cull above- // already handled that; `expect` would panic on a race between the two- // calls, so re-derive defensively and skip instead.+ // Re-derived defensively: a far-side race with the cull above skips, not panics. match camera.globe_anchor_to_screen(puck.lon, puck.lat) { Some((sx, sy)) => super::placement::globe_screen_quad(camera, sx, sy, PUCK_QUAD_DP as f64), None => return,@@ -458,6 +456,10 @@ impl Renderer { } else { camera.screen_quad_to_clip(puck.lon, puck.lat, PUCK_QUAD_DP as f64) };+ // Behind the eye under tilt (w <= 0): the quad would invert across the screen.+ if puck_matrix[15] <= 0.0 {+ return;+ } let push = Push { tile_to_clip: puck_matrix, color: argb_to_rgba(PUCK_COLOR),
library/map/src/main/rust/src/vulkan/renderer/record_extra3.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_extra3.rs b/library/map/src/main/rust/src/vulkan/renderer/record_extra3.rsindex 7b6d65767a..4f16d3d9ab 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_extra3.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_extra3.rs@@ -79,12 +79,11 @@ impl Renderer { let mut text_vertices: Vec<f32> = Vec::new(); let mut text_indices: Vec<u32> = Vec::new(); for (i, marker) in markers.iter().enumerate() {- let Some((sprite, cx, cy, xu, yu, xv, yv, w)) =+ let Some((sprite, cx, cy, xu, yu, xv, yv, _)) = marker_screen_geom(camera, marker, globe) else { continue; };- let _ = w; // Draw the icon at `MARKER_SIZE_DP` on its larger side, keeping its aspect ratio. With // `radius_dp = 1.0` above, a local coordinate is one Dp, so these half-extents are Dp. // (On the globe the quad is axis-aligned clip — same units, same math.) The extents@@ -109,7 +108,7 @@ impl Renderer { (corners[2].0, corners[2].1, uv.u1, v1), (corners[3].0, corners[3].1, uv.u0, v1), ];- emit_marker_corners(&mut vertices, &mut indices, base, corners, cx, cy, xu, yu, xv, yv, w);+ emit_marker_corners(&mut vertices, &mut indices, base, corners, cx, cy, xu, yu, xv, yv); // The name beside the icon, POI-style: shaped with the glyph atlas, laid out in Dp // to the icon's right, and hung off the same counter-rotated axes so it sits beside // the upright icon rather than wherever the bearing turned the map to.
library/map/src/main/rust/src/vulkan/renderer/record_extra4.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_extra4.rs b/library/map/src/main/rust/src/vulkan/renderer/record_extra4.rsindex b2bc9d7943..13d777c551 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_extra4.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_extra4.rs@@ -145,25 +145,9 @@ impl Renderer { self.step_times .borrow_mut() .record(Step::RecordBuildings, nanos_since(step_start));- let step_start = std::time::Instant::now();- for &(key, index) in deferred_symbols.iter() {- self.record_symbol(- command_buffer,- key,- index,- &layers[index],- camera,- palette,- accepted,- submitted,- bound,- binds,- globe,- );- }- self.step_times- .borrow_mut()- .record(Step::RecordSymbols, nanos_since(step_start));+ // Traffic and turn arrows are basemap detail drawn over the roads, and the rail lines+ // are a basemap-like overlay: all three go under the labels so road names and POIs are+ // not buried beneath them. let step_start = std::time::Instant::now(); self.record_traffic(command_buffer, camera, submitted, culled, binds, globe); self.step_times@@ -179,24 +163,48 @@ impl Renderer { // plane; bending them is a follow-up, and a route drawn flat over a ball // is worse than no route. Navigation always zooms past the globe // threshold anyway, so this only affects a zoomed-out preview.+ let mut rail_nanos = 0; if !globe { let rail_start = std::time::Instant::now(); self.record_rail_lines(command_buffer, camera, submitted, binds);- self.step_times- .borrow_mut()- .record(Step::RecordRail, nanos_since(rail_start));- // No route slot: it shares `record_route_buffers` with the rail lines, so its cost- // rides on `RecordRail` rather than a slot that reads zero on route-less frames.- self.record_route(command_buffer, camera, submitted, binds);+ rail_nanos = nanos_since(rail_start); }- // Region mask on the globe: skipped with the route (flat-plane stencil- // over a depth-tested ball). A selected region's mask reappears on zoom-in.+ let step_start = std::time::Instant::now();+ for &(key, index) in deferred_symbols.iter() {+ self.record_symbol(+ command_buffer,+ key,+ index,+ &layers[index],+ camera,+ palette,+ accepted,+ submitted,+ bound,+ binds,+ globe,+ );+ }+ self.step_times+ .borrow_mut()+ .record(Step::RecordSymbols, nanos_since(step_start));+ // The region scrim dims the whole basemap, labels included, so it follows them; the+ // route follows the scrim so a route you are following is never dimmed (see above).+ // Region mask on the globe: skipped with the route (flat-plane stencil). A selected+ // region's mask reappears on zoom-in. if !globe { let step_start = std::time::Instant::now(); self.record_region_mask(command_buffer, camera, submitted, culled, binds); self.step_times .borrow_mut() .record(Step::RecordRegion, nanos_since(step_start));+ // The route shares `record_route_buffers` with the rail lines, so its cost rides on+ // `RecordRail` rather than a slot that reads zero on route-less frames.+ let route_start = std::time::Instant::now();+ self.record_route(command_buffer, camera, submitted, binds);+ self.step_times+ .borrow_mut()+ .record(Step::RecordRail, rail_nanos + nanos_since(route_start)); } let step_start = std::time::Instant::now(); self.record_overlays(command_buffer, camera, palette, submitted, binds, globe);
library/map/src/main/rust/src/vulkan/renderer/record_markers.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_markers.rs b/library/map/src/main/rust/src/vulkan/renderer/record_markers.rsindex a26d676948..953b48f53e 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_markers.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_markers.rs@@ -172,9 +172,9 @@ pub(super) fn emit_marker_label( } /// Emit one marker's four corners into the shared sprite vertex/index buffers. ///-/// `corners` are (local_u, local_v, tex_u, tex_v); (cx, cy) the clip-space-/// centre; (xu, yu)/(xv, yv) the local Dp axes in clip space; `w` the-/// perspective divisor (1.0 on the globe path).+/// `corners` are (local_u, local_v, tex_u, tex_v); (cx, cy) the NDC centre and+/// (xu, yu)/(xv, yv) the local Dp axes in NDC, both already divided by the+/// marker's `w` in [`marker_screen_geom`], so the corners add straight on. pub(super) fn emit_marker_corners( vertices: &mut Vec<f32>, indices: &mut Vec<u32>,@@ -186,13 +186,10 @@ pub(super) fn emit_marker_corners( yu: f64, xv: f64, yv: f64,- w: f64, ) { for (lu, lv, tu, tv) in corners {- // Flat path: perspective divide by the marker's own w. Globe path:- // axis-aligned clip axes with w == 1, so this is the same add.- let ox = (lu * xu + lv * xv) / w;- let oy = (lu * yu + lv * yv) / w;+ let ox = lu * xu + lv * xv;+ let oy = lu * yu + lv * yv; vertices.push((cx + ox) as f32); vertices.push((cy + oy) as f32); vertices.push(tu);
library/map/src/main/rust/src/vulkan/renderer/record_moon.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_moon.rs b/library/map/src/main/rust/src/vulkan/renderer/record_moon.rsindex 437950b73e..13e56fe332 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_moon.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_moon.rs@@ -17,7 +17,7 @@ impl Renderer { /// disc radius fills the globe the Earth path would have drawn at this /// zoom (same `globe_radius`), centred on the viewport, so switching bodies /// never moves the planet under the finger.- pub(super) fn render_moon(&mut self, camera: &Camera) -> Result<bool, String> {+ pub(super) fn render_moon(&mut self, camera: &Camera, clear: u32) -> Result<bool, String> { if self.needs_rebuild { self.rebuild()?; self.needs_rebuild = false;@@ -65,7 +65,7 @@ impl Renderer { device .reset_fences(std::slice::from_ref(&in_flight)) .map_err(|e| format!("reset_fences {e:?}"))?;- self.record_moon(command_buffer, image_index as usize, camera)?;+ self.record_moon(command_buffer, image_index as usize, camera, clear)?; let wait_stages = [vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT]; let submit = vk::SubmitInfo::default() .wait_semaphores(std::slice::from_ref(&image_available))@@ -103,13 +103,11 @@ impl Renderer { command_buffer: vk::CommandBuffer, image_index: usize, camera: &Camera,+ // The same theme-following clear the vector frame uses (`style::background` of the+ // palette variant).+ clear: u32, ) -> Result<(), String> {- use crate::style; let device = &self.context.device;- // Same clear as the vector frame: the water-blue is the Earth sea, but on- // the Moon it reads as space only if dark — the maps host drives the Moon- // from the same dark-palette path, so the clear follows the theme.- let clear = style::background(crate::style::Variant::Light); Self::begin_frame_pass( device, command_buffer,@@ -149,7 +147,7 @@ impl Renderer { // rect, so no new vertex path. The quad vertices are -1..1 already; the // matrix maps them to the disc: scale = globe diameter in clip units, // centred on the viewport centre.- let r_dp = crate::camera::globe_radius(camera.zoom);+ let r_dp = crate::camera::globe_radius(camera.zoom, camera.center_lat); let kx = 2.0 / camera.width_dp as f64; let ky = 2.0 / camera.height_dp as f64; let disc = [
library/map/src/main/rust/src/vulkan/renderer/record_symbol.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_symbol.rs b/library/map/src/main/rust/src/vulkan/renderer/record_symbol.rsindex c1c96dd393..64b1998611 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_symbol.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_symbol.rs@@ -49,7 +49,7 @@ impl Renderer { // globe pipelines with the sphere matrix (centre + radius in the matrix); // `misc.x` keeps its flat meaning (tile span, Dp) and `morph` carries the // globe half-viewport + radius (see `symbol_globe.vert`).- let r = crate::camera::globe_radius(camera.zoom) as f32;+ let r = crate::camera::globe_radius(camera.zoom, camera.center_lat) as f32; let (globe_misc, globe_morph) = if globe { ( [camera.tile_span_dp(tz) as f32, 0.0, 0.0, 0.0],
library/map/src/main/rust/src/vulkan/renderer/upload.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/upload.rs b/library/map/src/main/rust/src/vulkan/renderer/upload.rsindex 10236f776a..a50a65d507 100644--- a/library/map/src/main/rust/src/vulkan/renderer/upload.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/upload.rs@@ -260,6 +260,13 @@ impl Renderer { }) } };+ // A same-key replacement (toggle/palette re-tessellation) keeps the original stamp:+ // its pixels were already on screen, so restarting the fade would flash it transparent.+ let uploaded_at = self+ .tiles+ .get(&key)+ .map(|previous| previous.uploaded_at)+ .unwrap_or_else(|| self.last_camera.map(|c| c.time_seconds).unwrap_or(0.0)); let tile = upload_tail::assemble_tile( &pooled_buffers, (flat, lines, ribbons),@@ -270,7 +277,7 @@ impl Renderer { buildings, terrain, mesh,- self.last_camera.map(|c| c.time_seconds).unwrap_or(0.0),+ uploaded_at, ); if let Some(previous) = self.tiles.insert(key, tile) { self.retire(previous);
library/map/src/main/rust/src/vulkan/renderer/upload_tail.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/upload_tail.rs b/library/map/src/main/rust/src/vulkan/renderer/upload_tail.rsindex dd8952334c..157c8cc9ad 100644--- a/library/map/src/main/rust/src/vulkan/renderer/upload_tail.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/upload_tail.rs@@ -395,10 +395,12 @@ pub fn retain(renderer: &mut Renderer, keep: &[u64], visible: &[select::TileId], .collect(); ranked.sort_unstable(); + // Over the cap, stand-ins go first and on-screen tiles never: evicting a visible tile+ // only refetches it next frame, and a tilted view can need more tiles than the cap holds. let doomed: Vec<u64> = ranked .iter() .enumerate()- .filter(|(at, (rank, _))| *rank == 3 || *at >= cap)+ .filter(|(at, (rank, _))| *rank == 3 || (*at >= cap && *rank != 0)) .map(|(_, (_, key))| *key) .collect(); if doomed.is_empty() {