From 4074596213fdb6ef40d7257918d2fc4d86faed03 Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Wed, 13 Mar 2024 13:02:21 +0100
Subject: [PATCH] update: some progress, one more row split sort of

---
 .../__pycache__/get_relation.cpython-311.pyc  | Bin 6792 -> 7480 bytes
 server/map/get_relation.py                    |  31 +++++++++++++-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc
index e35a7a0bbb24aae68e2c04bf6f3fd9fadf1b0f4e..d8abc88c3545f0521eb620e7ff3bbd18cdadcf63 100644
GIT binary patch
delta 1401
zcmaJ<O>7%Q6rQzX@48v9H*xB}n%IeD95+#0C!nCl2?({cDk2pGj=^=a8?&jic4s&I
zm^DsO4i@Sm!a{W=D)|7#RjZP!9CGA@IPO|2VOgqV4n1%)DoBV6y!G16Ppdx7eDmJC
z@BNLY{Oay$<_D+q2m-nP&7b_Gu?Ni0ZmaMY@lbPb5hWYkTVX%>%7V}hq@Zo$+PrMA
zdjj_Ce!Dmz8~mPd#BBnhyRc0mPzDukij}hzpk((1$Eu}hSI`->e6C0;cFyYW)6r`R
zxdw$zS+RU-xzbfJ4YYwhTJJU{S_pJKqS$KIO4@mJmONbiKx?+c-s|TT8+OZ%$^&Ph
z#MygEhYkcilafPANFMCB2s7C@Y75<S+=jOAK5e~7DFX_%f3h`uKc-j50}M;SiBNF>
zw6iZH?-*o?JF@oz&!qc6K{XOyVWje&=NQq~d?N>@88n}uvhDGfUYKqN(kaBMWeFMc
z8aqxe76#7?a(F#0h+$zh^ZCgAbH5k1UdP7J*a1-R8UB1u5alp%q<mJ8Q_@H2JdZy#
z+)gnUUddsR$5QxoX=3H+F9D~ayJ0_J0gQjQ2B#@dn^=q!cpl6+(IWDaK@Q_L0RN?u
z+4TBlF1=8Q<a7CrY+B}1BL7K>=Q8|>WHz^w&PofQn517IM4|vT(WRZMKS`SizX=v(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4L5v{ZiW?*1IV|7e*%E43B-K(V=EAJKGUy;<wfJg50X
zHPtA#)vMk@5P{hF<3T{f(rv!!&}mMm{qL!p*N=`bpZRYZs1P?Ai##^Pm8oC`lr*l0
h3*zx-4Nlf~BWa1u=p?`QIsgnm2BDvy=GZ;__&?!Zx6S|n

diff --git a/server/map/get_relation.py b/server/map/get_relation.py
index b80b3bf2..ae404a2c 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
 
+
-- 
GitLab