diff --git a/server/__init__.py b/server/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/server/__pycache__/__init__.cpython-311.pyc b/server/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bf3b3ede5d466fd1f57005a0cd3d95c10b6df960 Binary files /dev/null and b/server/__pycache__/__init__.cpython-311.pyc differ diff --git a/server/map_handler/__init__.py b/server/map_handler/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/server/map_handler/__pycache__/__init__.cpython-311.pyc b/server/map_handler/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fb4ed4cc033ec9499f21e0c2025401f1fe3a135d Binary files /dev/null and b/server/map_handler/__pycache__/__init__.cpython-311.pyc differ diff --git a/server/map_handler/__pycache__/add_new_lake.cpython-311.pyc b/server/map_handler/__pycache__/add_new_lake.cpython-311.pyc index 16eb848c6c0ecf96a3d721fd22b4de5d91527f39..a3599d330d3de9c7f28b5755675f91ddc48c6d37 100644 Binary files a/server/map_handler/__pycache__/add_new_lake.cpython-311.pyc and b/server/map_handler/__pycache__/add_new_lake.cpython-311.pyc differ diff --git a/server/map_handler/add_new_lake.py b/server/map_handler/add_new_lake.py index aa6b9c8b5b814d029e6b980279465ba496a335d3..b9d22c5ee92c543483307cceb2b5fdb01ea0aed6 100644 --- a/server/map_handler/add_new_lake.py +++ b/server/map_handler/add_new_lake.py @@ -5,7 +5,7 @@ from math import cos import geopandas as gpd from matplotlib import pyplot as plt from shapely.ops import linemerge, unary_union, polygonize -from shapely.geometry import Polygon, LineString, MultiLineString +from shapely.geometry import Polygon, LineString from server.consts import LAKE_RELATIONS_PATH @@ -148,20 +148,20 @@ def create_grid(poly: Polygon, cell_width: float, cell_height: float): # List to store all created lines grid_lines = [] - # Create new horizontal lines while within bounds - y = min_y - while y <= max_y: - line = LineString([(min_x, y), (max_x, y)]) - grid_lines.append(line) - y += cell_height - - # Create new vertical lines while within bounds + # Create vertical lines while within bounds x = min_x while x <= max_x: line = LineString([(x, min_y), (x, max_y)]) grid_lines.append(line) x += cell_width + # Create horizontal lines while within bounds + y = min_y + while y <= max_y: + line = LineString([(min_x, y), (max_x, y)]) + grid_lines.append(line) + y += cell_height + return grid_lines @@ -199,10 +199,10 @@ def write_json_to_file(lake_name: str, map_data: dict): # to plot the map after each division to ensure that the map was divided as intended. def plot_map(divided_map): """ - Plots a divided map using matplotlib. + Plots the divisions of a map using matplotlib. Parameters: - divided_map (list): List of Shapely Polygons + divided_map (list): List of Shapely Polygons to be plotted """ print("Plotting... This may take some time...") diff --git a/server/map_handler/unit_tests/__pycache__/__init__.cpython-311.pyc b/server/map_handler/unit_tests/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e32275e71c689422f02eb9cfd73c66597799718f Binary files /dev/null and b/server/map_handler/unit_tests/__pycache__/__init__.cpython-311.pyc differ diff --git a/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc b/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1f1035be606616e46806e57a11add5fc28a65bbd Binary files /dev/null and b/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc differ diff --git a/server/map_handler/unit_tests/test_add_new_lake.py b/server/map_handler/unit_tests/test_add_new_lake.py index cc2442a5f511e2be80b77ff2a8ea91bf97972991..8bde724889f7cf999af4c49f1a77632e36958798 100644 --- a/server/map_handler/unit_tests/test_add_new_lake.py +++ b/server/map_handler/unit_tests/test_add_new_lake.py @@ -1,5 +1,16 @@ +from shapely.geometry import Polygon, LineString + from server.map_handler.add_new_lake import create_grid -#def tes_create_grid_default(): - #grid = create_grid(0.2, 0.3) - #assert \ No newline at end of file + +def test_create_grid_default(): + # Create a simple square polygon + test_poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) + + # Define the expected grid output + coordinates = [[(0, 0), (0, 1)], [(0.5, 0), (0.5, 1)], [(1, 0), (1, 1)], + [(0, 0), (1, 0)], [(0, 0.4), (1, 0.4)], [(0, 0.8), (1, 0.8)]] + expected = [LineString(coords) for coords in coordinates] + + grid = create_grid(test_poly, 0.5, 0.4) + assert grid == expected