def test_int2coord(): with pytest.raises(AssertionError): hilbert._int2coord(0, 0, 0) # we always get lower left corner of coding cell # only one coding cell assert (-180, -90) == hilbert._int2coord(0, 0, 1) # lvl 2 is 4 cells: 2 in every direction assert (-180, -90) == hilbert._int2coord(0, 0, 2) assert (0, -90) == hilbert._int2coord(1, 0, 2) assert (-180, 0) == hilbert._int2coord(0, 1, 2) assert (0, 0) == hilbert._int2coord(1, 1, 2)
def test_coord2int2coord(): for lvl in range(1, 30): lng_err, lat_err = hilbert._lvl_error(lvl) dim = 1 << lvl for _i in range(1000): lng, lat = rand_lng(), rand_lat() x, y = hilbert._coord2int(lng, lat, dim) lng_x, lat_y = hilbert._int2coord(x, y, dim) # we always get lower left corner of coding cell # hence add error and then we have +- error assert lng == pytest.approx(lng_x + lng_err, abs=lng_err) assert lat == pytest.approx(lat_y + lat_err, abs=lat_err)