You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
689 B
35 lines
689 B
import org.junit.jupiter.api.Test
|
|
|
|
class CoordPackTest {
|
|
|
|
@Test
|
|
fun packUnpack() {
|
|
val xOrig = -0x1
|
|
val yOrig = 0x1
|
|
|
|
val coords = pack(xOrig, yOrig)
|
|
|
|
val xNew = x(coords)
|
|
val yNew = y(coords)
|
|
|
|
println("done")
|
|
|
|
assert(xOrig == xNew)
|
|
assert(yOrig == yNew)
|
|
|
|
|
|
}
|
|
|
|
fun pack(mostSignificantBits: Int, leastSignificantBits: Int): ULong {
|
|
return (mostSignificantBits.toUInt().toULong() shl 32) or leastSignificantBits.toUInt().toULong()
|
|
}
|
|
|
|
fun x(coords: ULong): Int {
|
|
return (coords shr 32).toLong().toInt()
|
|
}
|
|
fun y(coords: ULong): Int {
|
|
return coords.toLong().toInt()
|
|
}
|
|
|
|
|
|
} |