Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error Dialog and Don't allow user to draw mis-shapen polygons #3056

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

anandwana001
Copy link
Collaborator

@anandwana001 anandwana001 commented Feb 19, 2025

Fixes #2604

@shobhitagarwal1612 PTAL?

Screen.Recording.2025-02-19.at.6.40.32.PM.mov

@shobhitagarwal1612
Copy link
Member

As per the issue description, the button's text in the dialog should be OK.

Comment on lines +113 to +114
val showDialog = remember { mutableStateOf(true) }
if (showDialog.value) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this. ConfirmationDialog already maintains an internal state for visiblity

@@ -167,13 +184,21 @@ internal constructor(
}

fun completePolygon() {
check(LineString(vertices).isClosed()) { "Polygon is not complete" }
Copy link
Member

Choose a reason for hiding this comment

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

Why have we removed this check?

Comment on lines +22 to +34
fun orientation(a: Coordinates, b: Coordinates, c: Coordinates): Int {
val value = (b.lat - a.lat) * (c.lng - b.lng) - (b.lng - a.lng) * (c.lat - b.lat)
return when {
value > 0 -> 1 // Clockwise
value < 0 -> -1 // Counter-clockwise
else -> 0 // Collinear
}
}

fun onSegment(a: Coordinates, b: Coordinates, c: Coordinates): Boolean {
return c.lat in minOf(a.lat, b.lat)..maxOf(a.lat, b.lat) &&
c.lng in minOf(a.lng, b.lng)..maxOf(a.lng, b.lng)
}
Copy link
Member

Choose a reason for hiding this comment

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

These can be pulled out and made private.

import com.google.android.ground.model.geometry.Coordinates

/** Checks if two line segments intersect. */
fun segmentsIntersect(p1: Coordinates, p2: Coordinates, q1: Coordinates, q2: Coordinates): Boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Please use a better function name

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.

[Draw area] Don't allow user to draw mis-shapen polygons
2 participants