in src/mapillary/utils/format.py [0:0]
def normalize_list(coordinates: list, width: int = 4096, height: int = 4096) -> list:
"""
Normalizes a list of coordinates with the respective width and the height
From::
>>> [[[2402, 2776], [2408, 2776]]]
To::
>>> normalize_list(coordinates)
... # [[[0.58642578125, 0.677734375], [0.587890625, 0.677734375]]]
:param coordinates: The coordinate list to normalize
:type coordinates: list
:param width: The width of the coordinates to normalize with, defaults to 4096
:type width: int
:param height: The height of the coordinates to normalize with, defaults to 4096
:type height: int
:return: The normalized list
:rtype: list
"""
# Extracting the list from the coordinates
coordinates = coordinates[0]
# Initializing the coordinate list
new_coordinates = []
# Going through each coordinate pair
for coordinate_pair in coordinates:
# If it is already normalized ...
if 0 <= coordinate_pair[0] <= 1 and 0 <= coordinate_pair[1] <= 1:
# ... then append as is
new_coordinates.append(coordinate_pair)
# Appending the coordinates
new_coordinates.append(
# Appending a list pair of the width, height
[coordinate_pair[0] / width, coordinate_pair[1] / height]
)
# Returning the results
return [new_coordinates]