Skip to content

Commit

Permalink
Use safe distance check
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Jul 20, 2024
1 parent e798010 commit 9092ffe
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import me.gabber235.typewriter.entry.entity.*
import me.gabber235.typewriter.entry.entries.*
import me.gabber235.typewriter.entry.roadnetwork.RoadNetworkManager
import me.gabber235.typewriter.entry.roadnetwork.gps.PointToPointGPS
import me.gabber235.typewriter.utils.distanceSqrt
import org.koin.core.component.KoinComponent
import org.koin.java.KoinJavaComponent

Expand Down Expand Up @@ -70,7 +71,7 @@ private class PatrolActivity(
// Get the closest node to the start location
val closestNode = network.nodes
.filter { it.id in nodes }
.minByOrNull { it.location.distanceSquared(startLocation.toLocation()) }
.minByOrNull { it.location.distanceSqrt(startLocation.toLocation()) ?: Double.MAX_VALUE }
?: throw IllegalStateException("Could not find any node in the nodes list for the patrol activity.")

val index = nodes.indexOf(closestNode.id)
Expand Down

0 comments on commit 9092ffe

Please sign in to comment.