diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index e35a7a0bbb24aae68e2c04bf6f3fd9fadf1b0f4e..d8abc88c3545f0521eb620e7ff3bbd18cdadcf63 100644 Binary files a/server/map/__pycache__/get_relation.cpython-311.pyc and b/server/map/__pycache__/get_relation.cpython-311.pyc differ diff --git a/server/map/get_relation.py b/server/map/get_relation.py index b80b3bf2044adac31f0b1dc72211147e7c8d01e6..ae404a2c66752e83e59bd89caf2d11d03441c07c 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -157,7 +157,7 @@ def create_grid_coords(polygon: Polygon, cell_size: float): # NB: only for testing def circle_polygon(): circle_points = [] - num_points = 200 + num_points = 500 center_x, center_y = 0.0, 0.0 radius = 6 @@ -174,28 +174,43 @@ def circle_polygon(): # Adds equally spaced points along an edge that is created after a polygon is cut. def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: float): # Prepend new points onto the newly created edge to facilitate vertical splitting - if len(split_shape) > 2 and polygon_min_x is not None: + if split_shape is not None and polygon_min_x is not None: # Define starting point with an x-value that will be common for all polygons starting_point = polygon_min_x - # Get corners of the newly created shape which make up the new edge - right_corner = split_shape[-1] - left_corner = split_shape[0] + print("Hit main if") + # Create list of corners + corners = [] - print("right_corner: ", right_corner, " left_corner: ", left_corner, " cell_size: ", cell_size) + divisor_range = ((divisor - 0.01),(divisor + 0.01)) - while starting_point < left_corner.x: # Increment starting point until it is withing the polygons bounds + # Find all corners of split shape. Corner = point that intersects divisor + for point in split_shape: + if divisor_range[0] < point.y < divisor_range[1]: + corners.append(point) + print("Hit point in split_shape") + + if not corners or len(corners) < 2: + print("no corners :(") + return None + + # Sort corners in ascending order (left to right) based on x coordinate + sorted_corners = sorted(corners, key=lambda p: p.x) + + while starting_point < sorted_corners[0].x: # Increment starting point until it is withing the polygons bounds starting_point += cell_size # if starting_point < left_corner.x: # NB: optimised substitute for previous while loop, requires testing # starting_point += cell_size * math.floor(starting_point - left_corner.x) # Insert new points with cell_size spacing while starting_point is within bounds - while starting_point < right_corner.x: + while starting_point < sorted_corners[-1].x: split_shape.insert(0, (starting_point, divisor)) # NB may have to add/subtract small offset of 0.00001 remaining_shape.insert(0, (starting_point, divisor)) # Prepend new point to shape + print("Hit point insertion") starting_point += cell_size return split_shape, remaining_shape +