Skip to content

Conversation

anandwana001
Copy link
Collaborator

Fixes #3234

This PR introduces a full system to detect and handle polygon self-intersections:

Implemented isSelfIntersecting(vertices) to check for crossing edges, with support for both open polylines and closed polygons.

Integrated validation into the workflow:
Add Point: checks the newly added edge, reverts the vertex, and shows a dialog if self-intersection is detected.
Complete Polygon: validates the would-be closed ring (vertices + first), blocking completion and showing a dialog if invalid.
Ensured the intersection flag resets when geometry is valid, preventing stale “intersecting” states.
Updated onFeatureUpdated to disable the Complete button when a polygon is invalid.

Added unit tests covering:
Open and closed polygons
Adjacent edges sharing vertices
True self-intersections (e.g., “X” shapes)
Edge cases like empty list, single point, or triangles

This provides reliable guardrails to prevent creating invalid polygons and ensures user feedback when intersections occur.

Screen.Recording.2025-08-21.at.9.16.31.AM.mov

@gino-m @jo-spek PTAL?

Copy link

codecov bot commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 78.57143% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.17%. Comparing base (a435ed8) to head (2d652ba).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...acollection/tasks/polygon/DrawAreaTaskViewModel.kt 46.66% 4 Missing and 4 partials ⚠️
...tacollection/tasks/polygon/DrawAreaTaskFragment.kt 62.50% 0 Missing and 3 partials ⚠️
.../org/groundplatform/android/ui/util/PolygonUtil.kt 96.87% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3235   +/-   ##
=========================================
  Coverage     67.16%   67.17%           
- Complexity     1411     1415    +4     
=========================================
  Files           303      303           
  Lines          7642     7664   +22     
  Branches        774      785   +11     
=========================================
+ Hits           5133     5148   +15     
  Misses         2076     2076           
- Partials        433      440    +7     
Files with missing lines Coverage Δ
.../groundplatform/android/model/geometry/Geometry.kt 69.81% <100.00%> (ø)
.../org/groundplatform/android/ui/util/PolygonUtil.kt 89.58% <96.87%> (-0.42%) ⬇️
...tacollection/tasks/polygon/DrawAreaTaskFragment.kt 73.86% <62.50%> (-2.04%) ⬇️
...acollection/tasks/polygon/DrawAreaTaskViewModel.kt 81.11% <46.66%> (-0.98%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

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

@gino-m gino-m changed the title Add complete polygon self-intersection validation system [Draw/walk area task] Prevent user from drawing self-intersecting polygons Sep 9, 2025
@gino-m
Copy link
Collaborator

gino-m commented Sep 9, 2025

@anandwana001 Note I updated the PR description to reflect the new behavior rather than a description of the code

@gino-m gino-m self-requested a review September 23, 2025 13:49
@anandwana001 anandwana001 merged commit 17b1399 into master Sep 24, 2025
7 checks passed
@anandwana001 anandwana001 deleted the anandwana001/3234/complete-polygon-intersection branch September 24, 2025 02:38
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.

Mis-shapen polygon can be drawn through "Complete"
3 participants