Skip to content
Snippets Groups Projects
Commit 40745962 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: some progress, one more row split sort of

parent c4b0dadf
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
...@@ -157,7 +157,7 @@ def create_grid_coords(polygon: Polygon, cell_size: float): ...@@ -157,7 +157,7 @@ def create_grid_coords(polygon: Polygon, cell_size: float):
# NB: only for testing # NB: only for testing
def circle_polygon(): def circle_polygon():
circle_points = [] circle_points = []
num_points = 200 num_points = 500
center_x, center_y = 0.0, 0.0 center_x, center_y = 0.0, 0.0
radius = 6 radius = 6
...@@ -174,28 +174,43 @@ def circle_polygon(): ...@@ -174,28 +174,43 @@ def circle_polygon():
# Adds equally spaced points along an edge that is created after a polygon is cut. # 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): 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 # 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 # Define starting point with an x-value that will be common for all polygons
starting_point = polygon_min_x starting_point = polygon_min_x
# Get corners of the newly created shape which make up the new edge print("Hit main if")
right_corner = split_shape[-1] # Create list of corners
left_corner = split_shape[0] 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 starting_point += cell_size
# if starting_point < left_corner.x: # NB: optimised substitute for previous while loop, requires testing # 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) # starting_point += cell_size * math.floor(starting_point - left_corner.x)
# Insert new points with cell_size spacing while starting_point is within bounds # 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 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 remaining_shape.insert(0, (starting_point, divisor)) # Prepend new point to shape
print("Hit point insertion")
starting_point += cell_size starting_point += cell_size
return split_shape, remaining_shape return split_shape, remaining_shape
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment