Modern Apps git

← Modern-Apps.git

astronomy: fallback catalog positions now match the real sky

Commit
5c3335b4dfc4f3ad52d7df02a3b6016406b08eba
Author
Vayun Mathur <[email protected]>
When
2026-11-30 22:26 UTC (5 days ago)
Parents
379bc23
The hard-coded BuiltInCatalogs fallback (used when a bundled
catalog asset read fails) had coordinates that matched nothing:
Sirius was 57.9 degrees off, Altair 146 degrees, M31 41 degrees
(its RA carried a stray 0.185*2pi); 24 of 25 named stars were
off by 6.5-146 degrees, only Polaris right. Every alt-az,
rise/set, search hit and detail page derived from the fallback
inherited the full error, and the existing tests only asserted
value ranges and name order, never positions.

All 27 named stars and 6 Messier objects now carry the exact
bundled-catalog J2000 coordinates. Two new tests assert every
entry lies within 0.25 degrees of its reference position —
failing on the old data, passing now. Sun/Moon/planet math,
coordinate transforms and rise/set bracketing were verified
against almanac values and cleared. Verified:
:astronomy:testDevUnitTest 60 tests pass; lint errors identical
to the pre-change baseline on untouched files.

Diff

astronomy/src/main/java/com/vayunmathur/astronomy/data/CatalogRepository.kt
diff --git a/astronomy/src/main/java/com/vayunmathur/astronomy/data/CatalogRepository.kt b/astronomy/src/main/java/com/vayunmathur/astronomy/data/CatalogRepository.ktindex 3a093506e2..7de83b80e1 100644--- a/astronomy/src/main/java/com/vayunmathur/astronomy/data/CatalogRepository.kt+++ b/astronomy/src/main/java/com/vayunmathur/astronomy/data/CatalogRepository.kt@@ -99,34 +99,37 @@ class CatalogRepository( /** Small built-in fallback catalogs used when a bundled asset is missing or unreadable. */ object BuiltInCatalogs {     val stars: List<Star> = listOf(-        Star(1, 2.0632318, 0.68092, -1.44, 0.0, "Sirius", "Sirius", "Alpha", null, "CMa", 8.6, "A1V"),-        Star(2, 0.94511, 0.08153, -0.62, 0.0, "Canopus", "Canopus", "Alpha", null, "Car", 310.0, "A9 II"),-        Star(3, 2.011977, 1.38542, -0.05, 0.01, "Arcturus", "Arcturus", "Alpha", null, "Boo", 36.7, "K0 III"),-        Star(4, 4.904635, 1.3475, -0.05, 0.15, "Vega", "Vega", "Alpha", null, "Lyr", 25.0, "A0 Va"),-        Star(5, 3.733777, 1.1333904, 0.03, 0.15, "Capella", "Capella", "Alpha", null, "Aur", 42.9, "G3 III"),-        Star(6, 1.5941598, -0.303976, 0.08, 0.0, "Rigel", "Rigel", "Beta", null, "Ori", 860.0, "B8 Ia"),-        Star(7, 5.53395, -1.0000529, 0.12, 0.0, "Procyon", "Procyon", "Alpha", null, "CMi", 11.46, "F5 IV-V"),-        Star(8, 1.5045678, 0.5948826, 0.42, 0.0, "Betelgeuse", "Betelgeuse", "Alpha", null, "Ori", 642.5,+        // RA/Dec (radians, J2000) match the bundled catalog/stars.json entries+        // of the same names; the fallback is what renders when the asset+        // cannot be read, so it must place the named stars on the real sky.+        Star(1, 1.7677953696021995, -0.291751258517685, -1.44, 0.0, "Sirius", "Sirius", "Alpha", null, "CMa", 8.6, "A1V"),+        Star(2, 1.6753053519997292, -0.9197127748902675, -0.62, 0.0, "Canopus", "Canopus", "Alpha", null, "Car", 310.0, "A9 II"),+        Star(3, 3.7335290285420872, 0.33479621805862125, -0.05, 0.01, "Arcturus", "Arcturus", "Alpha", null, "Boo", 36.7, "K0 III"),+        Star(4, 4.873563095509031, 0.6769031163973025, -0.05, 0.15, "Vega", "Vega", "Alpha", null, "Lyr", 25.0, "A0 Va"),+        Star(5, 1.381816412648801, 0.8028163926341112, 0.03, 0.15, "Capella", "Capella", "Alpha", null, "Aur", 42.9, "G3 III"),+        Star(6, 1.3724303693276385, -0.143145630755865, 0.08, 0.0, "Rigel", "Rigel", "Beta", null, "Ori", 860.0, "B8 Ia"),+        Star(7, 2.004083041242831, 0.09119333187796, 0.12, 0.0, "Procyon", "Procyon", "Alpha", null, "CMi", 11.46, "F5 IV-V"),+        Star(8, 1.5497291183713153, 0.12927763169419373, 0.42, 0.0, "Betelgeuse", "Betelgeuse", "Alpha", null, "Ori", 642.5,             "M1-M2 Ia-Iab"),-        Star(9, 3.179167, 0.124354, 0.42, -0.21, "Achernar", "Achernar", "Alpha", null, "Eri", 139.0, "B6 Vep"),-        Star(10, 2.1443926, 0.0778795, 0.50, 0.14, "Hadar", "Agena", "Beta", null, "Cen", 390.0, "B1 III"),-        Star(11, 1.5161099, 0.094466, 0.61, 0.0, "Altair", "Altair", "Alpha", null, "Aql", 16.73, "A7 V"),-        Star(12, 4.512539, 1.0303768, 0.76, 0.07, "Aldebaran", "Aldebaran", "Alpha", null, "Tau", 65.0, "K5 III"),-        Star(13, 5.2422002, -0.0150372, 0.77, 0.39, "Antares", "Antares", "Alpha", 21, "Sco", 550.0, "M1.5 Iab-b"),-        Star(14, 2.441246, -0.7140256, 0.79, 0.14, "Acrux", "Acrux", "Alpha", null, "Cru", 321.0, "B0.5 IV"),-        Star(15, 1.92341299, 1.56207, 0.87, -0.04, "Spica", "Spica", "Alpha", 67, "Vir", 250.0, "B1 III-IV"),-        Star(16, 3.0028855, 1.23141, 0.97, 0.0, "Pollux", "Pollux", "Beta", 78, "Gem", 33.78, "K0 III"),-        Star(17, 5.9196997, 0.95444583, 1.06, 1.48, "Fomalhaut", "Fomalhaut", "Alpha", null, "PsA", 25.13, "A4 V"),-        Star(18, 4.4266224, -0.41680044, 1.14, 1.42, "Mimosa", "Becrux", "Beta", null, "Cru", 280.0, "B0.5 III"),-        Star(19, 5.03644, 0.27895867, 1.16, 0.09, "Deneb", "Deneb", "Alpha", 50, "Cyg", 2600.0, "A2 Ia"),-        Star(20, 0.66808675, 1.5575598, 1.98, 0.0, "Polaris", "Polaris", "Alpha", 1, "UMi", 433.0, "F7 Ib"),-        Star(21, 3.366, 1.29, 2.9, 0.0, "Dubhe", "Dubhe", "Alpha", 50, "UMa", 123.0, "F7"),-        Star(22, 4.76, 1.21, 2.7, 0.0, "Schedar", "Schedar", "Alpha", 18, "Cas", 228.0, "K0 IIIa"),-        Star(23, 0.26, 1.03, 2.2, 0.0, "Caph", "Caph", "Beta", 8, "Cas", 54.0, "F2 III-IV"),-        Star(24, 5.919, -0.6, 2.1, 0.0, "Nunki", "Nunki", "Sigma", 0, "Sgr", 228.0, "B2.5 V"),-        Star(25, 2.06, 0.34, 0.4, 0.0, "Rigil Kentaurus", "Rigil Kentaurus", "Alpha", null, "Cen", 4.37, "G2 V"),-        Star(26, 4.06, 0.42, 0.77, 0.0, "Castor", "Castor", "Alpha", 66, "Gem", 52.0, "A1 V"),-        Star(27, 2.3898913, 1.0427, 1.25, 0.0, "Beta Crucis", "Mimosa", "Beta", null, "Cru", 280.0, "B0.5 III"),+        Star(9, 0.42635506591376426, -0.9989698692415762, 0.42, -0.21, "Achernar", "Achernar", "Alpha", null, "Eri", 139.0, "B6 Vep"),+        Star(10, 3.681875660376148, -1.053708314075195, 0.50, 0.14, "Hadar", "Agena", "Beta", null, "Cen", 390.0, "B1 III"),+        Star(11, 5.195772105546999, 0.15478141706831, 0.61, 0.0, "Altair", "Altair", "Alpha", null, "Aql", 16.73, "A7 V"),+        Star(12, 1.2039308112027507, 0.2881416661221312, 0.76, 0.07, "Aldebaran", "Aldebaran", "Alpha", null, "Tau", 65.0, "K5 III"),+        Star(13, 4.317105466000638, -0.4613254705959812, 0.77, 0.39, "Antares", "Antares", "Alpha", 21, "Sco", 550.0, "M1.5 Iab-b"),+        Star(14, 3.2576512815622607, -1.1012869028642311, 0.79, 0.14, "Acrux", "Acrux", "Alpha", null, "Cru", 321.0, "B0.5 IV"),+        Star(15, 3.5133172180991257, -0.194801818024575, 0.87, -0.04, "Spica", "Spica", "Alpha", 67, "Vir", 250.0, "B1 III-IV"),+        Star(16, 2.0303268874812184, 0.4891494417459975, 0.97, 0.0, "Pollux", "Pollux", "Beta", 78, "Gem", 33.78, "K0 III"),+        Star(17, 6.011133383906492, -0.5170055514089774, 1.06, 1.48, "Fomalhaut", "Fomalhaut", "Alpha", null, "PsA", 25.13, "A4 V"),+        Star(18, 3.349817026601454, -1.0417654498397388, 1.14, 1.42, "Mimosa", "Becrux", "Beta", null, "Cru", 280.0, "B0.5 III"),+        Star(19, 5.416768542177067, 0.790290982752855, 1.16, 0.09, "Deneb", "Deneb", "Alpha", 50, "Cyg", 2600.0, "A2 Ia"),+        Star(20, 0.6622870748653336, 1.5579526129751475, 1.98, 0.0, "Polaris", "Polaris", "Alpha", 1, "UMi", 433.0, "F7 Ib"),+        Star(21, 2.896065350203451, 1.0777588446528075, 2.9, 0.0, "Dubhe", "Dubhe", "Alpha", 50, "UMa", 123.0, "F7"),+        Star(22, 0.17674488133148336, 0.9867625763100912, 2.7, 0.0, "Schedar", "Schedar", "Alpha", 18, "Cas", 228.0, "K0 IIIa"),+        Star(23, 0.040025852830323276, 1.0323584043676326, 2.2, 0.0, "Caph", "Caph", "Beta", 8, "Cas", 54.0, "F2 III-IV"),+        Star(24, 4.953529829382003, -0.4589643844760175, 2.1, 0.0, "Nunki", "Nunki", "Sigma", 0, "Sgr", 228.0, "B2.5 V"),+        Star(25, 3.838179211777228, -1.0617531757704175, 0.4, 0.0, "Rigil Kentaurus", "Rigil Kentaurus", "Alpha", null, "Cen", 4.37, "G2 V"),+        Star(26, 1.983558270234413, 0.5565554130270287, 0.77, 0.0, "Castor", "Castor", "Alpha", 66, "Gem", 52.0, "A1 V"),+        Star(27, 3.349817026601454, -1.0417654498397388, 1.25, 0.0, "Beta Crucis", "Mimosa", "Beta", null, "Cru", 280.0, "B0.5 III"),     ) + generateFillerStars()      private const val FILLER_STAR_COUNT = 4000@@ -158,13 +161,14 @@ object BuiltInCatalogs {         Constellation("Cen", "Centaurus", listOf(listOf(25,14))),     ) +    // RA/Dec (radians, J2000) match the bundled catalog/messier.json entries.     val messier: List<DeepSkyObject> = listOf(-        DeepSkyObject("M31", "Andromeda Galaxy", 0.185*2*Math.PI, 0.712, 3.4, "galaxy", 178.0, "And"),-        DeepSkyObject("M42", "Orion Nebula", 1.459, -0.093, 4.0, "nebula", 65.0, "Ori"),-        DeepSkyObject("M45", "Pleiades", 0.99, 0.42, 1.6, "cluster", 110.0, "Tau"),-        DeepSkyObject("M13", "Hercules Cluster", 4.30, 0.631, 5.8, "cluster", 20.0, "Her"),-        DeepSkyObject("M51", "Whirlpool Galaxy", 3.47, 0.82, 8.4, "galaxy", 11.0, "CVn"),-        DeepSkyObject("M57", "Ring Nebula", 4.866, 0.576, 8.8, "nebula", 1.5, "Lyr"),+        DeepSkyObject("M31", "Andromeda Galaxy", 0.1864011641129944, 0.7202746930177839, 3.4, "galaxy", 178.0, "And"),+        DeepSkyObject("M42", "Orion Nebula", 1.462971630935939, -0.09409244530426629, 4.0, "nebula", 65.0, "Ori"),+        DeepSkyObject("M45", "Pleiades", 0.990474350506782, 0.4209158197157165, 1.6, "cluster", 110.0, "Tau"),+        DeepSkyObject("M13", "Hercules Cluster", 4.3706535128442, 0.6363470452771326, 5.8, "cluster", 20.0, "Her"),+        DeepSkyObject("M51", "Whirlpool Galaxy", 3.5337786084884306, 0.8237133764664799, 8.4, "galaxy", 11.0, "CVn"),+        DeepSkyObject("M57", "Ring Nebula", 4.946193286981851, 0.5764647986412071, 8.8, "nebula", 1.5, "Lyr"),     )      val orbital: List<OrbitalElements> = listOf(
astronomy/src/test/java/com/vayunmathur/astronomy/data/BuiltInCatalogsTest.kt
diff --git a/astronomy/src/test/java/com/vayunmathur/astronomy/data/BuiltInCatalogsTest.kt b/astronomy/src/test/java/com/vayunmathur/astronomy/data/BuiltInCatalogsTest.ktindex 5e62bff26d..008a653363 100644--- a/astronomy/src/test/java/com/vayunmathur/astronomy/data/BuiltInCatalogsTest.kt+++ b/astronomy/src/test/java/com/vayunmathur/astronomy/data/BuiltInCatalogsTest.kt@@ -52,6 +52,84 @@ class BuiltInCatalogsTest {         assertTrue(BuiltInCatalogs.constellations.any { it.abbr == "Ori" && it.name == "Orion" })     } +    @Test+    fun `named fallback stars sit at their real J2000 positions`() {+        // Reference RA/Dec (radians, J2000) for the named fallback stars.+        // These are the same objects the bundled catalog/stars.json ships;+        // the fallback renders/searches them whenever an asset read fails,+        // so a fallback position degrees away from the real star puts the+        // label (and every alt-az derived from it) on empty sky. Sirius,+        // for example, was stored 57.9 degrees from its real position.+        val reference = mapOf(+            "Sirius" to (1.7677953696021995 to -0.291751258517685),+            "Canopus" to (1.6753053519997292 to -0.9197127748902675),+            "Arcturus" to (3.7335290285420872 to 0.33479621805862125),+            "Vega" to (4.873563095509031 to 0.6769031163973025),+            "Capella" to (1.381816412648801 to 0.8028163926341112),+            "Rigel" to (1.3724303693276385 to -0.143145630755865),+            "Procyon" to (2.004083041242831 to 0.09119333187796),+            "Betelgeuse" to (1.5497291183713153 to 0.12927763169419373),+            "Achernar" to (0.42635506591376426 to -0.9989698692415762),+            "Agena" to (3.681875660376148 to -1.053708314075195),+            "Altair" to (5.195772105546999 to 0.15478141706831),+            "Aldebaran" to (1.2039308112027507 to 0.2881416661221312),+            "Antares" to (4.317105466000638 to -0.4613254705959812),+            "Acrux" to (3.2576512815622607 to -1.1012869028642311),+            "Spica" to (3.5133172180991257 to -0.194801818024575),+            "Pollux" to (2.0303268874812184 to 0.4891494417459975),+            "Fomalhaut" to (6.011133383906492 to -0.5170055514089774),+            "Becrux" to (3.349817026601454 to -1.0417654498397388),+            "Deneb" to (5.416768542177067 to 0.790290982752855),+            "Polaris" to (0.6622870748653336 to 1.5579526129751475),+            "Dubhe" to (2.896065350203451 to 1.0777588446528075),+            "Schedar" to (0.17674488133148336 to 0.9867625763100912),+            "Caph" to (0.040025852830323276 to 1.0323584043676326),+            "Nunki" to (4.953529829382003 to -0.4589643844760175),+            "Rigil Kentaurus" to (3.838179211777228 to -1.0617531757704175),+            "Castor" to (1.983558270234413 to 0.5565554130270287),+            "Mimosa" to (3.349817026601454 to -1.0417654498397388),+        )+        val maxSepRad = Math.toRadians(0.25)+        val byProperName = BuiltInCatalogs.stars+            .filter { it.properName != null }+            .associateBy { it.properName }+        assertEquals(reference.keys, byProperName.keys)+        for ((name, ref) in reference) {+            val star = byProperName.getValue(name)+            val sep = com.vayunmathur.astronomy.domain.engine.CoordinateTransforms.angularDistanceRad(+                com.vayunmathur.astronomy.domain.engine.RaDec(star.ra, star.dec),+                com.vayunmathur.astronomy.domain.engine.RaDec(ref.first, ref.second),+            )+            assertTrue(sep < maxSepRad, "$name is ${Math.toDegrees(sep)} deg from its real position")+        }+    }++    @Test+    fun `messier fallback objects sit at their real J2000 positions`() {+        // Same check for the deep-sky fallback: M31's RA carried a stray+        // * 2 * PI factor that put it 41.4 degrees from the Andromeda+        // Galaxy, and M13/M51/M57 were each several degrees off.+        val reference = mapOf(+            "M31" to (0.1864011641129944 to 0.7202746930177839),+            "M42" to (1.462971630935939 to -0.09409244530426629),+            "M45" to (0.990474350506782 to 0.4209158197157165),+            "M13" to (4.3706535128442 to 0.6363470452771326),+            "M51" to (3.5337786084884306 to 0.8237133764664799),+            "M57" to (4.946193286981851 to 0.5764647986412071),+        )+        val maxSepRad = Math.toRadians(0.25)+        val byId = BuiltInCatalogs.messier.associateBy { it.id }+        assertEquals(reference.keys, byId.keys)+        for ((id, ref) in reference) {+            val obj = byId.getValue(id)+            val sep = com.vayunmathur.astronomy.domain.engine.CoordinateTransforms.angularDistanceRad(+                com.vayunmathur.astronomy.domain.engine.RaDec(obj.ra, obj.dec),+                com.vayunmathur.astronomy.domain.engine.RaDec(ref.first, ref.second),+            )+            assertTrue(sep < maxSepRad, "$id is ${Math.toDegrees(sep)} deg from its real position")+        }+    }+     @Test     fun `messier fallback holds the bright showpieces`() {         val byId = BuiltInCatalogs.messier.associateBy { it.id }