def normalize_bearing()

in mapillary_tools/geo.py [0:0]


def normalize_bearing(bearing: float, check_hex: bool = False) -> float:
    """
    Normalize bearing and convert from hex if
    """
    if bearing > 360 and check_hex:
        # fix negative value wrongly parsed in exifread
        # -360 degree -> 4294966935 when converting from hex
        bearing1 = bin(int(bearing))[2:]
        bearing2 = "".join([str(int(int(a) == 0)) for a in bearing1])
        bearing = -float(int(bearing2, 2))
    bearing %= 360
    return bearing