Created
August 7, 2020 15:04
-
-
Save Xzonn/39a3cd9f180ed3663b1cf21018094ff8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def ZOrderX(tileSize, count): | |
div = tileSize // 2; | |
x_in = count // div & div; | |
while div > 1: | |
div = div // 2; | |
x_in |= count // div & div; | |
return x_in; | |
def ZOrderY(tileSize, count): | |
div = tileSize; | |
div2 = tileSize // 2; | |
y_in = count // div & div2; | |
while div2 > 1: | |
div = div //2; | |
div2 = div2 //2; | |
y_in |= count // div & div2; | |
return y_in; | |
def getPointSequence(width, height, orientation = False, tileSize = 8, zOrder = True): | |
strideWidth, strideHeight = (width + 7) & ~7, (height + 7) & ~ 7; | |
if zOrder: | |
tileSize = 2 << int(math.log(((tileSize + 7) & ~7) - 1, 2)); | |
powTileSize = int(tileSize ** 2); | |
stride = strideWidth; | |
for i in range(strideWidth * strideHeight): | |
x_out, y_out, x_in, y_in = 0, 0, 0, 0; | |
if zOrder: | |
x_out = (i // powTileSize % (stride // tileSize)) * tileSize; | |
y_out = (i // powTileSize // (stride // tileSize)) * tileSize; | |
x_in = ZOrderX(tileSize, i); | |
y_in = ZOrderY(tileSize, i); | |
yield (x_out + x_in, y_out + y_in); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment