Skip to content

Commit

Permalink
Added validation for bbox input
Browse files Browse the repository at this point in the history
Merge pull request #45 from louis-e/bbox-validation
  • Loading branch information
louis-e authored Aug 18, 2024
2 parents ee49015 + 6f34b12 commit 2ad01f8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,45 @@
mcWorldPath = mcWorldPath[:-1]


def validate_bounding_box(bbox):
"""
Validates a bounding box represented as a string in
the format "min_lng,min_lat,max_lng,max_lat".
Parameters:
bbox (str): The bounding box string.
Returns:
bool: True if the bounding box is valid, False otherwise.
"""
try:
# Split the input string into components
parts = bbox.split(",")
if len(parts) != 4:
return False

# Convert the components to float
min_lng, min_lat, max_lng, max_lat = map(float, parts)

# Validate the longitude range (-180 to 180)
if not (-180 <= min_lng <= 180 and -180 <= max_lng <= 180):
return False

# Validate the latitude range (-90 to 90)
if not (-90 <= min_lat <= 90 and -90 <= max_lat <= 90):
return False

# Ensure that min_lng is less than max_lng and min_lat is less than max_lat
if min_lng >= max_lng or min_lat >= max_lat:
return False

return True

except ValueError:
# In case of conversion error, input was not a valid float
return False


def run():
print(
"""\n
Expand All @@ -92,6 +131,11 @@ def run():
print("Error! No Minecraft world found at given path")
os._exit(1)

if args.bbox:
if validate_bounding_box(args.bbox) is False:
print("Error! Invalid bbox input")
os._exit(1)

rawdata = getData(
args.city,
args.state,
Expand Down

0 comments on commit 2ad01f8

Please sign in to comment.