From ec2950305dd35318772fb93a81b965399624f4b6 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sun, 15 Dec 2024 12:07:51 +0200 Subject: [PATCH] perf: faster vector -> direction conversion --- .../tilegroups/layers/TileLayerTerrain.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt index 0777f987c2..e6686ba37f 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt @@ -253,14 +253,18 @@ enum class NeighborDirection { Top, TopRight, TopLeft, Bottom, BottomLeft, BottomRight; companion object { - fun fromVector(vector2: Vector2): NeighborDirection? = when { - vector2.x == 1f && vector2.y == 1f -> Top - vector2.x == 0f && vector2.y == 1f -> TopRight - vector2.x == 1f && vector2.y == 0f -> TopLeft - vector2.x == -1f && vector2.y == -1f -> Bottom - vector2.x == 0f && vector2.y == -1f -> BottomLeft - vector2.x == -1f && vector2.y == 0f -> BottomRight - else -> null + fun fromVector(vector2: Vector2): NeighborDirection? { + val x = vector2.x.toInt() + val y = vector2.y.toInt() + return when (x) { + 1 -> if (y == 1) Top // x == 1 && y == 1 + else TopLeft // x == 1 && y == 0 + 0 -> if (y == 1) TopRight // x == 0 && y == 1 + else BottomLeft // x == 0 && y == -1 + -1 -> if (y == -1) Bottom // x == -1 && y == -1 + else BottomRight // x == -1 && y == 0 + else -> null + } } } }