From 41fb8a18e7283ee6b557abd8e96aa8ea6eb15056 Mon Sep 17 00:00:00 2001 From: Jordan Longstaff Date: Mon, 9 Sep 2024 16:19:19 -0400 Subject: [PATCH] Fix one Detekt issue in RoutingGraph.kt --- app/detekt-baseline.xml | 1 - .../kotlin/artemis/agent/cpu/RoutingGraph.kt | 37 ++++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/detekt-baseline.xml b/app/detekt-baseline.xml index e39d6af9..178320da 100644 --- a/app/detekt-baseline.xml +++ b/app/detekt-baseline.xml @@ -2,7 +2,6 @@ - ComplexCondition:RoutingGraph.kt$RoutingGraph.Companion$sourceX.isNaN() || sourceZ.isNaN() || destX.isNaN() || destZ.isNaN() CyclomaticComplexMethod:AgentViewModel.kt$AgentViewModel$private suspend fun updateObjects() CyclomaticComplexMethod:AlliesFragment.kt$AlliesFragment$override fun onViewCreated(view: View, savedInstanceState: Bundle?) CyclomaticComplexMethod:AlliesFragment.kt$AlliesFragment.AllyInfoBinder$fun bind(entry: Ally, viewModel: AgentViewModel) diff --git a/app/src/main/kotlin/artemis/agent/cpu/RoutingGraph.kt b/app/src/main/kotlin/artemis/agent/cpu/RoutingGraph.kt index a46ee768..bea31b7b 100644 --- a/app/src/main/kotlin/artemis/agent/cpu/RoutingGraph.kt +++ b/app/src/main/kotlin/artemis/agent/cpu/RoutingGraph.kt @@ -879,26 +879,27 @@ internal class RoutingGraph( sourceZ: Float, destX: Float, destZ: Float - ): Float { - if (sourceX.isNaN() || sourceZ.isNaN() || destX.isNaN() || destZ.isNaN()) { - return Float.NaN - } - - val dx = destX - sourceX - val dz = destZ - sourceZ - val simpleDistance = sqrt(dx * dx + dz * dz) - return if (this == null || viewModel.playerShip?.driveType?.value != DriveType.WARP) { - simpleDistance - } else { - calculateAvoidanceRouteCost( - sourceX, - sourceZ, - destX, - destZ, + ): Float = + if (allDefined(sourceX, sourceX, destX, destZ)) { + val dx = destX - sourceX + val dz = destZ - sourceZ + val simpleDistance = sqrt(dx * dx + dz * dz) + if (this == null || viewModel.playerShip?.driveType?.value != DriveType.WARP) { simpleDistance - ) + } else { + calculateAvoidanceRouteCost( + sourceX, + sourceZ, + destX, + destZ, + simpleDistance + ) + } + } else { + Float.NaN } - } + + private fun allDefined(vararg coordinates: Float): Boolean = coordinates.none(Float::isNaN) /** * Generates a "route key" representing a path from one object to another, encapsulating