From df083840ac5a814d68245b20ed6fe0f277176cdf Mon Sep 17 00:00:00 2001 From: atsunatsu Date: Mon, 3 Aug 2026 03:03:08 +0800 Subject: [PATCH] fix: use independent search algorithm directly, no passes list reuse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The passes list AOS/LOS times can be stale or computed for a different station position, causing elevation curves to show -60° at pass start. The independent search (refineEdge + sampleMutualPass) always computes elevation for the actual positions. With posA now set to the exact station position, the pass times should match the main page. --- .../feature/mutual/MutualViewModel.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/feature/mutual/src/main/java/com/rtbishop/look4sat/feature/mutual/MutualViewModel.kt b/feature/mutual/src/main/java/com/rtbishop/look4sat/feature/mutual/MutualViewModel.kt index 5b69fff0..87c2334e 100644 --- a/feature/mutual/src/main/java/com/rtbishop/look4sat/feature/mutual/MutualViewModel.kt +++ b/feature/mutual/src/main/java/com/rtbishop/look4sat/feature/mutual/MutualViewModel.kt @@ -85,7 +85,7 @@ class MutualViewModel( val state = _uiState.value // Resolve positions from lat/lon or grid - val posA = resolvePosition(state.stationALat, state.stationALon, state.stationAGrid) + var posA = resolvePosition(state.stationALat, state.stationALon, state.stationAGrid) val posB = resolvePosition(state.stationBLat, state.stationBLon, state.stationBGrid) if (posA == null || posB == null) { @@ -93,6 +93,15 @@ class MutualViewModel( return } + // When station A's grid matches the pre-filled grid (user hasn't changed it), + // use the exact station position from settings so the pass times and elevation + // curves are consistent with the main Passes page. + val stationPos = settingsRepo.stationPosition.value + val prefillGrid = latLonToGrid(stationPos.latitude, stationPos.longitude) + if (state.stationAGrid.trim().uppercase() == prefillGrid) { + posA = stationPos + } + val satellites = satelliteRepo.satellites.value if (satellites.isEmpty()) { _uiState.update { it.copy(errorMessage = "没有卫星数据,请先在卫星列表中选择卫星") } @@ -221,16 +230,6 @@ class MutualViewModel( ): List { val endTime = time + hours * 60L * 60L * 1000L val sampleInterval = 5_000L - - // Priority: reuse the main page's pass list (calculated by getLeoPass) - // so mutual pass times match the main page exactly. - val existingPasses = satelliteRepo.passes.value - val results = findMutualPassesFromList(existingPasses, satellites, posA, posB, - minElevADeg, minElevBDeg, time, endTime, sampleInterval) - if (results.isNotEmpty()) return results - - // Fallback: if the main pass list is empty or the common window is too narrow, - // search independently (same algorithm as before, with 0° horizon boundary). return findMutualPassesFallback(satellites, posA, posB, minElevADeg, minElevBDeg, time, endTime, sampleInterval) }