Modern Apps git

← Modern-Apps.git

maps astronomy: fix scan recursion, inverse hour angle, positionless mask

Commit
48810ca57df31cd34e39d8092ba80dbd1fcb4692
Author
vayun-mathur <[email protected]>
When
2026-10-22 00:09 UTC (1 month ago)
Parents
dc48249

Diff

astronomy/src/main/java/com/vayunmathur/astronomy/domain/engine/CoordinateTransforms.kt
diff --git a/astronomy/src/main/java/com/vayunmathur/astronomy/domain/engine/CoordinateTransforms.kt b/astronomy/src/main/java/com/vayunmathur/astronomy/domain/engine/CoordinateTransforms.ktindex 66ec66214a..d78be57ddc 100644--- a/astronomy/src/main/java/com/vayunmathur/astronomy/domain/engine/CoordinateTransforms.kt+++ b/astronomy/src/main/java/com/vayunmathur/astronomy/domain/engine/CoordinateTransforms.kt@@ -41,9 +41,14 @@ object CoordinateTransforms {         val sinDec = sin(altAz.altRad) * sin(latRad) +             cos(altAz.altRad) * cos(latRad) * cos(altAz.azRad)         val dec = asin(sinDec.coerceIn(-1.0, 1.0))+        // Inverts raDecToAltAz exactly: from sinH = -sinAz*cosAlt/cosDec and+        // cosH = (sinAlt-sinDec*sinLat)/(cosDec*cosLat), multiply both by the+        // positive factor cosDec*cosLat so no division can blow up. The old+        // second argument mixed the azimuth convention and returned hour+        // angles off by up to hundreds of degrees.         val ha = atan2(-            -cos(altAz.altRad) * sin(altAz.azRad),-            cos(altAz.altRad) * cos(altAz.azRad) * sin(latRad) - sin(altAz.altRad) * cos(latRad),+            -sin(altAz.azRad) * cos(altAz.altRad) * cos(latRad),+            sin(altAz.altRad) - sinDec * sin(latRad),         )         val ra = (lstRad - ha).normalize2Pi()         return RaDec(ra, dec)
maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.ktindex b38289bcb7..c4d39dd45d 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt@@ -269,16 +269,17 @@ internal suspend fun openVehicleTrip(  * The selected label's outline, dimmed outside. Derived from the sheet's own  * selection rather than the tap, so a region picked from search masks too — and the  * mask is the label's baked `regionId`, so no point/level guess: linked masks exactly- * that region, unlinked (`0` / absent) masks nothing.+ * that region, unlinked (`0` / absent) masks nothing. A label with no position+ * cannot be placed on the map, so it masks nothing even when linked.  */ internal fun regionMaskFor(     selectedFeature: com.vayunmathur.maps.data.SpecificFeature?, ): Long? = when (selectedFeature) {     is com.vayunmathur.maps.data.SpecificFeature.Admin0Label ->-        selectedFeature.regionId.takeIf { it != 0L }+        selectedFeature.regionId.takeIf { it != 0L && selectedFeature.position != null }     is com.vayunmathur.maps.data.SpecificFeature.Admin1Label ->-        selectedFeature.regionId.takeIf { it != 0L }+        selectedFeature.regionId.takeIf { it != 0L && selectedFeature.position != null }     is com.vayunmathur.maps.data.SpecificFeature.Admin2Label ->-        selectedFeature.regionId.takeIf { it != 0L }+        selectedFeature.regionId.takeIf { it != 0L && selectedFeature.position != null }     else -> null }
maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.ktindex 124837f57b..875859a9e8 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt@@ -610,13 +610,16 @@ object PoiIndex {     ): List<PoiRecord> = searchByWordIndex(m, query, nearLat, nearLon, limit, CANDIDATE_CAP)      // Scan search lives in PoiIndexWords.kt; this delegates so searchByName is unchanged.+    // (This must call the package-level function there: calling itself+    // recurses forever — StackOverflowError on every scan-path search.)     private fun searchByScan(         m: Mapped,         query: String,         nearLat: Double,         nearLon: Double,         limit: Int,-    ): List<PoiRecord> = searchByScan(m, query, nearLat, nearLon, limit)+    ): List<PoiRecord> =+        com.vayunmathur.maps.util.searchByScan(m, query, nearLat, nearLon, limit)      // Spatial queries (nearest/inViewport) live in PoiIndexSpatial.kt as     // extensions, alongside the grid they walk.