TerrainTileMath

Standard XYZ/slippy-map Web Mercator tile math, self-contained here (rather than reused from either flavor's own copy — feature/map-maplibre's TileEstimate.kt and the Google flavor's WebMercatorTileMath in the sibling feat/map-google-pmtiles-offline branch) so this module has no dependency in either direction on flavor-specific code — this module is a shared math library, not a consumer of one flavor's app code.

Functions

Link copied to clipboard
fun fitsInSingleTile(zoom: Int, bounds: GeoBounds): Boolean

Whether bounds fits entirely inside a single tile at zoom — used for Mapterhorn's regional-archive gate.

Link copied to clipboard
fun lonLatAt(tile: TileIndex, localX: Float, localY: Float): LonLat

Inverse of tileAt: the geographic point at a fractional position within tilelocalX/localY in the tile's own [0,1]×[0,1] unit square, the same convention ContourPoint uses. Needed to place contour geometry (which ContourGenerator emits tile-local) on a real map; nothing here needed the inverse before.

Link copied to clipboard
fun tileAt(zoom: Int, latitude: Double, longitude: Double): TileIndex
Link copied to clipboard
fun tileCountAt(zoom: Int, bounds: GeoBounds): Long

How many tiles tilesAt would return for zoom/bounds, computed from the two corner indices rather than by materializing the list — stays O(1) per zoom regardless of how large the actual count is. Shared by TerrainRegionExtractor (to bound memory before enumerating) and :feature:map-maplibre's own pre-download estimate shown in the layers sheet.

Link copied to clipboard
fun tilesAt(zoom: Int, bounds: GeoBounds): List<TileIndex>

Every tile in bounds at zoom, inclusive of both corners' own tiles. Antimeridian-aware — see xRangesAt.