def decode(big_str, coords, base, m): """Decodes big number back to delta coordinates Args: big_str: Big string encoding as returned by heuristic.big_encode coords: Delta coordinates of the original polygon used for created big string base Returns: True if the decoded list of delta coordinates matches original delta coordinates `coords`. False otherwise. """ for i in [1,2]: M = helpers.base_decode(big_str[:i], base) M = M + 2 big_num = helpers.base_decode(big_str[i:], base) z = big_num/const.y_factor Dy_min = big_num - const.y_factor * z big_num = z z = big_num/const.x_factor Dx_min = big_num - const.x_factor * z big_num = z deltas = [] flagged = False while big_num > 0: m = big_num % M big_num = big_num / M deltas.append(int(m)) deltas = deltas[::-1] deltas[0] -= 1 deltas[1] -= 1 if deltas == coords: return True
def invert_golomb_trans(s, base, e): bs = e result = '' count = 0 m = 2**e d = helpers.base_decode(s, base) b = bin(d)[3:] while count < 2: zi = b.find('0') if zi: b = b[zi+1:] v = (zi*m + int(b[:bs], 2)) * m v += int(b[bs:2*bs], 2) else: b = b[zi+1:] v = int(b[:bs], 2) * m v += int(b[bs:2*bs], 2) b = b[2*bs:] result += str(v) + ',' count += 1 while b: zi = b.find('0') b = b[zi+1:] result += str(zi*m + int(b[:bs], 2)) + ',' b = b[bs:] return ''.join(result[:-1])