Description
During a refactor of the DrawAreaTask state management to adhere to Unidirectional Data Flow (UDF) principles (#3678), several issues were identified in the polygon drawing logic that could lead to invalid geometry being saved and a confusing user experience.
Detected Issues
- Duplicate Points in Storage: Incomplete polygons were saving duplicate points (specifically duplicating the last vertex), resulting in 4 points instead of 3 for a triangle.
- Incorrect Undo Behavior: The Undo action would remove a committed vertex even when there was a tentative vertex actively being drawn on the screen.
- Missing Validation for Degenerate Shapes: The proximity check (
isTooClose) failed to trigger when closing a triangle with only 2 committed points, allowing degenerate lines to be formed.
- Premature Button Visibility: The
COMPLETE button was displayed for closed shapes that didn't have enough distinct points to form a valid polygon (requires 3 distinct points).
Proposed Fix
The implementation has been refactored in the current branch to:
- Separate committed vertices from the transient tentative vertex in the ViewModel state.
- Clear the tentative vertex upon commit.
- Enforce a minimum of 3 distinct points for closure validation.
- Update proximity checks to cover all edge cases when closing shapes.
- Introduce
PolygonDrawingSession class to encapsulate list of committed vertices, transient tentative vertex, redo stack, operations like adding a vertex, undoing, and redoing.
Steps to Reproduce
- Start drawing an area task.
- Place 3 points.
- Observe that the saved incomplete geometry contains 4 points instead of 3.
Description
During a refactor of the
DrawAreaTaskstate management to adhere to Unidirectional Data Flow (UDF) principles (#3678), several issues were identified in the polygon drawing logic that could lead to invalid geometry being saved and a confusing user experience.Detected Issues
isTooClose) failed to trigger when closing a triangle with only 2 committed points, allowing degenerate lines to be formed.COMPLETEbutton was displayed for closed shapes that didn't have enough distinct points to form a valid polygon (requires 3 distinct points).Proposed Fix
The implementation has been refactored in the current branch to:
PolygonDrawingSessionclass to encapsulate list of committed vertices, transient tentative vertex, redo stack, operations like adding a vertex, undoing, and redoing.Steps to Reproduce