Skip to content

Move spatial bounds and geometry calculations to :core:domain and remove GmsExt - #3911

Open
shobhitagarwal1612 wants to merge 6 commits into
masterfrom
layer-inversion
Open

Move spatial bounds and geometry calculations to :core:domain and remove GmsExt#3911
shobhitagarwal1612 wants to merge 6 commits into
masterfrom
layer-inversion

Conversation

@shobhitagarwal1612

@shobhitagarwal1612 shobhitagarwal1612 commented Aug 28, 2026

Copy link
Copy Markdown
Member

Towards #3633

Description

Removes presentation-layer GmsExt.kt and moves spherical geometry and bounding box calculations directly into :core:domain. This eliminates a Clean Architecture layer inversion where repositories and ViewModels depended on Google Maps SDK classes, while significantly reducing memory churn during map interactions.

Performance Improvements

  • Zero-Allocation Map Render Loop (60fps): Pattern-matched Bounds.contains(Geometry) to avoid calling getShellCoordinates(). This eliminates ephemeral listOf(coordinates) allocations for Point LOIs and eager ArrayList flattening for MultiPolygon on camera pan/zoom updates in BaseMapViewModel.
  • $O(N) \to O(1)$ Heap Allocations in Spatial Math: Eliminated transient Google Maps LatLng object allocations per vertex by computing areas and bounding boxes directly on domain primitives.

Functional & Architectural Changes

  • Eliminated GmsExt.kt: Migrated area(), center, and contains() to pure KMP domain models (Geometry.kt, Bounds.kt).
  • Spherical Area Parity: Added PolygonUtil.calculateSphericalPolygonArea matching SphericalUtil.computeArea using Girard's theorem / polar triangle excess.
  • Bounds Factories & Anti-Meridian Handling:
    • Replaced extension functions with explicit companion factories: Bounds.fromCoordinates, fromGeometry, and fromGeometries.
    • Added robust 180th meridian wrapping and normalization for Bounds.fromCoordinates(), shrink(), and center.
  • Testing: Added comprehensive unit tests in BoundsTest, GeometryTest, and PolygonUtilTest covering all edge cases.

@andreia-ferreira PTAL?

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.95575% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.26%. Comparing base (97da8be) to head (e86dfd0).

Files with missing lines Patch % Lines
...tlin/org/groundplatform/domain/model/map/Bounds.kt 90.00% 0 Missing and 7 partials ⚠️
...g/groundplatform/domain/model/geometry/Geometry.kt 69.23% 4 Missing ⚠️
...oundplatform/android/ui/common/BaseMapViewModel.kt 0.00% 2 Missing ⚠️
...ollection/tasks/polygon/DrawAreaTaskMapFragment.kt 0.00% 1 Missing ⚠️
...droid/ui/map/gms/features/FeatureClusterManager.kt 0.00% 1 Missing ⚠️
...tlin/org/groundplatform/domain/util/PolygonUtil.kt 95.00% 0 Missing and 1 partial ⚠️
...oundplatform/feature/pdf/mapper/LoiReportMapper.kt 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3911      +/-   ##
============================================
+ Coverage     68.98%   69.26%   +0.28%     
- Complexity     1946     1955       +9     
============================================
  Files           413      412       -1     
  Lines         10964    11015      +51     
  Branches       1429     1452      +23     
============================================
+ Hits           7563     7630      +67     
+ Misses         2656     2636      -20     
- Partials        745      749       +4     
Files with missing lines Coverage Δ
...android/repository/LocationOfInterestRepository.kt 65.26% <ø> (ø)
.../groundplatform/android/system/GeocodingManager.kt 92.10% <100.00%> (ø)
...acollection/tasks/polygon/DrawAreaTaskViewModel.kt 82.06% <100.00%> (ø)
...me/mapcontainer/HomeScreenMapContainerViewModel.kt 71.42% <ø> (ø)
...ollection/tasks/polygon/DrawAreaTaskMapFragment.kt 50.00% <0.00%> (ø)
...droid/ui/map/gms/features/FeatureClusterManager.kt 76.92% <0.00%> (ø)
...tlin/org/groundplatform/domain/util/PolygonUtil.kt 88.88% <95.00%> (-0.70%) ⬇️
...oundplatform/feature/pdf/mapper/LoiReportMapper.kt 91.54% <0.00%> (ø)
...oundplatform/android/ui/common/BaseMapViewModel.kt 62.99% <0.00%> (-0.50%) ⬇️
...g/groundplatform/domain/model/geometry/Geometry.kt 48.88% <69.23%> (+31.11%) ⬆️
... and 1 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shobhitagarwal1612
shobhitagarwal1612 marked this pull request as ready for review August 28, 2026 04:48

@andreia-ferreira andreia-ferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants