perf: faster vector -> direction conversion
Some checks failed
Conflict marking / main (push) Failing after 11s
Detekt / detekt (ubuntu-latest) (push) Failing after 51s
Generate mkdocs from docs folder / deploy (push) Failing after 14m57s
Build and test / Check code and run unit tests (push) Failing after 52m14s
Close stale issues and PRs / stale (push) Has started running
Docker / build (push) Has started running

This commit is contained in:
yairm210 2024-12-15 12:07:51 +02:00
parent 73424466d4
commit ec2950305d

View File

@ -253,14 +253,18 @@ enum class NeighborDirection {
Top, TopRight, TopLeft, Bottom, BottomLeft, BottomRight; Top, TopRight, TopLeft, Bottom, BottomLeft, BottomRight;
companion object { companion object {
fun fromVector(vector2: Vector2): NeighborDirection? = when { fun fromVector(vector2: Vector2): NeighborDirection? {
vector2.x == 1f && vector2.y == 1f -> Top val x = vector2.x.toInt()
vector2.x == 0f && vector2.y == 1f -> TopRight val y = vector2.y.toInt()
vector2.x == 1f && vector2.y == 0f -> TopLeft return when (x) {
vector2.x == -1f && vector2.y == -1f -> Bottom 1 -> if (y == 1) Top // x == 1 && y == 1
vector2.x == 0f && vector2.y == -1f -> BottomLeft else TopLeft // x == 1 && y == 0
vector2.x == -1f && vector2.y == 0f -> BottomRight 0 -> if (y == 1) TopRight // x == 0 && y == 1
else -> null else BottomLeft // x == 0 && y == -1
-1 -> if (y == -1) Bottom // x == -1 && y == -1
else BottomRight // x == -1 && y == 0
else -> null
}
} }
} }
} }