diff --git a/common/coords.go b/common/coords.go index da10333..0ab4585 100644 --- a/common/coords.go +++ b/common/coords.go @@ -11,8 +11,8 @@ import ( const ( numBitsPerComponent = 12 - maxPositive = 2048 - modulo = 4096 + modulo = 1 << numBitsPerComponent + maxPositive = modulo / 2 ) type ( @@ -92,7 +92,9 @@ func InterleavedToXYZ(c int64) (x, y, z int16) { } func XYZToPlain(x, y, z int16) int64 { - return int64(z)<<24 + int64(y)<<12 + int64(x) + return int64(z)<<(2*numBitsPerComponent) + + int64(y)<= 0 { - return i % modulo + return i & mask } - return modulo - (-i)%modulo + return modulo - -i&mask } // Only to match the C++ code. func PlainToXYZ(i int64) (x, y, z int16) { x = unsignedToSigned(pythonModulo(int16(i))) - i = (i - int64(x)) / modulo + i = (i - int64(x)) >> numBitsPerComponent y = unsignedToSigned(pythonModulo(int16(i))) - i = (i - int64(y)) / modulo + i = (i - int64(y)) >> numBitsPerComponent z = unsignedToSigned(pythonModulo(int16(i))) return }