From 9092ffeab7b277ca2d4d2ebb476555ea6273b178 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Sat, 20 Jul 2024 08:09:06 +0200 Subject: [PATCH] Use safe distance check --- .../me/gabber235/typewriter/entries/activity/PatrolActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adapters/EntityAdapter/src/main/kotlin/me/gabber235/typewriter/entries/activity/PatrolActivity.kt b/adapters/EntityAdapter/src/main/kotlin/me/gabber235/typewriter/entries/activity/PatrolActivity.kt index 3f57c3f3c3..67ae910844 100644 --- a/adapters/EntityAdapter/src/main/kotlin/me/gabber235/typewriter/entries/activity/PatrolActivity.kt +++ b/adapters/EntityAdapter/src/main/kotlin/me/gabber235/typewriter/entries/activity/PatrolActivity.kt @@ -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 @@ -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)