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;
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
}
}
}
}