From 52be2e6066b7368b1e5d75430ec5fa44ccf6ae26 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 6 Sep 2026 17:25:10 +0100 Subject: [PATCH] postit: tolerate nearby rdv map cache hits --- src/PostIt/PostIt.Tests/RdvPageTests.cs | 30 +++++++++++++++++++ .../PostIt/Views/Commands/RdvPage.axaml.cs | 16 ++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/PostIt/PostIt.Tests/RdvPageTests.cs diff --git a/src/PostIt/PostIt.Tests/RdvPageTests.cs b/src/PostIt/PostIt.Tests/RdvPageTests.cs new file mode 100644 index 000000000..e9d20cc96 --- /dev/null +++ b/src/PostIt/PostIt.Tests/RdvPageTests.cs @@ -0,0 +1,30 @@ +using PostIt.Views.Commands; + +namespace PostIt.Tests; + +public class RdvPageTests +{ + [Fact] + public void AreCoordinatesClose_returns_true_for_nearby_points_within_cache_tolerance() + { + var result = RdvPage.AreCoordinatesClose( + 48.8566, + 2.3522, + 48.85665, + 2.35225); + + Assert.True(result); + } + + [Fact] + public void AreCoordinatesClose_returns_false_for_points_outside_cache_tolerance() + { + var result = RdvPage.AreCoordinatesClose( + 48.8566, + 2.3522, + 48.85685, + 2.3522); + + Assert.False(result); + } +} \ No newline at end of file diff --git a/src/PostIt/PostIt/Views/Commands/RdvPage.axaml.cs b/src/PostIt/PostIt/Views/Commands/RdvPage.axaml.cs index 29953ea24..749d15cdd 100644 --- a/src/PostIt/PostIt/Views/Commands/RdvPage.axaml.cs +++ b/src/PostIt/PostIt/Views/Commands/RdvPage.axaml.cs @@ -22,6 +22,7 @@ public partial class RdvPage : ContentPage private const double DefaultLongitude = 2.3522; private const int DefaultZoomLevel = 4; private const int SelectedZoomLevel = 13; + internal const double ReverseGeocodingCacheToleranceDegrees = 0.0001; private static readonly TimeSpan ReverseGeocodingDebounce = TimeSpan.FromMilliseconds(350); private MapControl? _locationMap; @@ -183,8 +184,9 @@ public partial class RdvPage : ContentPage private async Task TryResolveAddressAsync(RdvViewModel vm, double latitude, double longitude) { - if (_lastResolvedLatitude == latitude - && _lastResolvedLongitude == longitude + if (_lastResolvedLatitude.HasValue + && _lastResolvedLongitude.HasValue + && AreCoordinatesClose(_lastResolvedLatitude.Value, _lastResolvedLongitude.Value, latitude, longitude) && !string.IsNullOrWhiteSpace(_lastResolvedAddress)) { vm.ApplyResolvedAddress(_lastResolvedAddress); @@ -221,4 +223,14 @@ public partial class RdvPage : ContentPage vm.IsResolvingAddress = false; } } + + internal static bool AreCoordinatesClose( + double latitudeA, + double longitudeA, + double latitudeB, + double longitudeB) + { + return Math.Abs(latitudeA - latitudeB) <= ReverseGeocodingCacheToleranceDegrees + && Math.Abs(longitudeA - longitudeB) <= ReverseGeocodingCacheToleranceDegrees; + } }