From 440ad116e606694390e138d39d2fb4395b68c97a Mon Sep 17 00:00:00 2001 From: stani-m <89606745+stani-m@users.noreply.github.com> Date: Fri, 27 Mar 2026 12:42:29 +0100 Subject: [PATCH 1/2] Fix LatLngBounds overlap calculation --- lib/src/geo/latlng_bounds.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 55e35f508..dcc908e1c 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -307,7 +307,7 @@ class LatLngBounds { delta += 360; } delta = delta.abs(); - return delta < longitudeWidth || delta < other.longitudeWidth; + return delta < (longitudeWidth + other.longitudeWidth) / 2; } @override From 1dbdb16df645dbbc94362fd506055b59bb67a7ce Mon Sep 17 00:00:00 2001 From: stani-m <89606745+stani-m@users.noreply.github.com> Date: Mon, 13 Apr 2026 21:52:54 +0200 Subject: [PATCH 2/2] Add tests for LatLng.isOverlapping method --- test/geo/latlng_bounds_test.dart | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/geo/latlng_bounds_test.dart b/test/geo/latlng_bounds_test.dart index 20c009c99..3842fcd15 100644 --- a/test/geo/latlng_bounds_test.dart +++ b/test/geo/latlng_bounds_test.dart @@ -94,5 +94,35 @@ void main() { expect(center.longitude, (-179.86 + 23.86) / 2); }); }); + + group('isOverlapping', () { + test('should not overlap', () { + final bounds1 = LatLngBounds( + const LatLng(49.622376, 18.286332), + const LatLng(48.721399, 20.122905), + ); + final bounds2 = LatLngBounds( + const LatLng(49.33295874620594, 20.58826958952466), + const LatLng(49.22512969150049, 20.676160214524646), + ); + + expect(bounds1.isOverlapping(bounds2), isFalse); + expect(bounds2.isOverlapping(bounds1), isFalse); + }); + + test('should overlap', () { + final bounds1 = LatLngBounds( + const LatLng(50, 20), + const LatLng(51, 21), + ); + final bounds2 = LatLngBounds( + const LatLng(50.5, 20.5), + const LatLng(51.5, 21.5), + ); + + expect(bounds1.isOverlapping(bounds2), isTrue); + expect(bounds2.isOverlapping(bounds1), isTrue); + }); + }); }); }