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

Find nearest vertex sample #319

Open
wants to merge 13 commits into
base: v.next
Choose a base branch
from
Open

Conversation

darryl-lynch
Copy link
Collaborator

Description

Adding more functionality to the create and edit geometries working branch

Links and Data

Issues: https://devtopia.esri.com/runtime/kotlin/issues/4989
vTest: https://runtime-kotlin.esri.com/view/all/job/vtest/job/sampleviewer/80/

What To Review

Review like ordinary sample. The delete button is of particular interest since a new dropdown was added to try make it fit and have sufficient detail on what it does. Will fail style checks as README will likely be part of final stage.

How to Test

Run the sample on the sample viewer or the repo.

@01smito01 01smito01 self-requested a review February 10, 2025 17:33
Copy link
Collaborator

@01smito01 01smito01 left a comment

Choose a reason for hiding this comment

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

Looks good, not much to add.

Comment on lines 182 to 183
val vertexDistance = ((nearestVertexResult?.distance)?.div(5280.0))?.toInt()!!
val coordinateDistance = ((nearestCoordinateResult?.distance)?.div(5280.0))?.toInt()!!
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's quite a lot going on here, would be a good idea to do the calculations for these in their own method.

Unchecked null asserts are also not a good idea - since vertexDistance and coordinateDistance are only used to update _distanceInformationFlow we can leave these nullable and do a check there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've fixed the unchecked null assert, but I can't find a good way to break up the calculation. I feel like if I did I'd need to take the source for the calculation out too, and then that would be 80% of the method anyway. It's less than ideal but this is how the original sample does it.

Copy link
Collaborator

@01smito01 01smito01 Feb 12, 2025

Choose a reason for hiding this comment

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

Did a search and 5280 is the number of feet in a mile. Can do an extension function on Double:

    /**
     * Converts a quantity in feet to miles.
     */
    private fun Double.feetToMiles(): Double {
        return this/5280.0
    }

which then allows this:

        val vertexDistance = nearestVertexResult?.distance?.feetToMiles()?.toInt()
        val coordinateDistance = nearestCoordinateResult?.distance?.feetToMiles()?.toInt()

Which is a bit more readable.
Could do the int conversion in the extension, but I think it's better to leave that as its own thing or move it into the call to DistanceInformation, or change the typing on DistanceInformation, (etc).

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