Skip to content

Commit

Permalink
Fix one Detekt issue in RoutingGraph.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanLongstaff committed Sep 9, 2024
1 parent a04a93f commit 41fb8a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
1 change: 0 additions & 1 deletion app/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>ComplexCondition:RoutingGraph.kt$RoutingGraph.Companion$sourceX.isNaN() || sourceZ.isNaN() || destX.isNaN() || destZ.isNaN()</ID>
<ID>CyclomaticComplexMethod:AgentViewModel.kt$AgentViewModel$private suspend fun updateObjects()</ID>
<ID>CyclomaticComplexMethod:AlliesFragment.kt$AlliesFragment$override fun onViewCreated(view: View, savedInstanceState: Bundle?)</ID>
<ID>CyclomaticComplexMethod:AlliesFragment.kt$AlliesFragment.AllyInfoBinder$fun bind(entry: Ally, viewModel: AgentViewModel)</ID>
Expand Down
37 changes: 19 additions & 18 deletions app/src/main/kotlin/artemis/agent/cpu/RoutingGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41fb8a1

Please sign in to comment.