def hilbert_point(dimension, order, h): """ Convert an index on the Hilbert curve of the specified dimension and order to a set of point coordinates. """ # The bit widths in this function are: # p[*] - order # h - order*dimension # l - dimension # e - dimension hwidth = order*dimension e, d = 0, 0 p = [0]*dimension for i in range(order): w = utils.bitrange(h, hwidth, i*dimension, i*dimension+dimension) l = utils.graycode(w) l = itransform(e, d, dimension, l) for j in range(dimension): b = utils.bitrange(l, dimension, j, j+1) p[j] = utils.setbit(p[j], order, i, b) e = e ^ utils.lrot(entry(w), d+1, dimension) d = (d + direction(w, dimension) + 1)%dimension return p
def hilbert_point(dimension, order, h): """ Convert an index on the Hilbert curve of the specified dimension and order to a set of point coordinates. """ # The bit widths in this function are: # p[*] - order # h - order*dimension # l - dimension # e - dimension hwidth = order * dimension e, d = 0, 0 p = [0] * dimension for i in range(order): w = utils.bitrange(h, hwidth, i * dimension, i * dimension + dimension) l = utils.graycode(w) l = itransform(e, d, dimension, l) for j in range(dimension): b = utils.bitrange(l, dimension, j, j + 1) p[j] = utils.setbit(p[j], order, i, b) e = e ^ utils.lrot(entry(w), d + 1, dimension) d = (d + direction(w, dimension) + 1) % dimension return p
def test_setbit(self): assert utils.setbit(0, 3, 0, 1) == 4 assert utils.setbit(4, 3, 2, 1) == 5 assert utils.setbit(4, 3, 0, 0) == 0