Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. # encode a 32x32x16 brick coordinate as a 128x128 coordinate, with
  2. # the z value sorted in morton order
  3.  
  4. def part2to4(x):
  5. x = x & 3 # not strictly necessary if value is clean
  6. return (x ^ (x << 1)) & 5
  7.  
  8. def compact4to2(x):
  9. x = x & 5
  10. return (x ^ (x >> 1)) & 3
  11.  
  12. def xy2z(x,y):
  13. return (part2to4(y)<<1) | part2to4(x)
  14.  
  15. def z2xy(z):
  16. return compact4to2(z), compact4to2(z>>1)
  17.  
  18. def xyz2xy(x,y,z):
  19. u,v = z2xy(z)
  20. return (x<<2)|u, (y<<2)|v
  21.  
  22. def xy2xyz(x,y):
  23. z = xy2z(x,y)
  24. return x>>2, y>>2, z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement