Skip to content

Commit 6908090

Browse files
committed
Fastvec coordinate no branching
1 parent f84fcd5 commit 6908090

File tree

1 file changed

+3
-12
lines changed
  • common/src/main/kotlin/com/lambda/util/world

1 file changed

+3
-12
lines changed

common/src/main/kotlin/com/lambda/util/world/Position.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,19 @@ fun fastVectorOf(x: Int, y: Int, z: Int): FastVector = fastVectorOf(x.toLong(),
6969
* Gets the X coordinate from the position.
7070
*/
7171
val FastVector.x: Int
72-
get() {
73-
val x = (this shr X_SHIFT and X_MASK).toInt()
74-
return if (x and (1 shl X_BITS - 1) != 0) x - (1 shl X_BITS) else x
75-
}
72+
get() = ((this shr X_SHIFT and X_MASK).toInt() shl (32 - X_BITS)) shr (32 - X_BITS)
7673

7774
/**
7875
* Gets the Z coordinate from the position.
7976
*/
8077
val FastVector.z: Int
81-
get() {
82-
val z = (this shr Z_SHIFT and Z_MASK).toInt()
83-
return if (z and (1 shl Z_BITS - 1) != 0) z - (1 shl Z_BITS) else z
84-
}
78+
get() = ((this shr Z_SHIFT and Z_MASK).toInt() shl (32 - Z_BITS)) shr (32 - Z_BITS)
8579

8680
/**
8781
* Gets the Y coordinate from the position.
8882
*/
8983
val FastVector.y: Int
90-
get() {
91-
val y = (this and Y_MASK).toInt()
92-
return if (y and (1 shl Y_BITS - 1) != 0) y - (1 shl Y_BITS) else y
93-
}
84+
get() = ((this and Y_MASK).toInt() shl (32 - Y_BITS)) shr (32 - Y_BITS)
9485

9586
/**
9687
* Sets the X coordinate of the position.

0 commit comments

Comments
 (0)