Update utils.py
Browse files
utils.py
CHANGED
@@ -240,26 +240,32 @@ def is_there_a_directed_edge(a, b, rects):
|
|
240 |
rectB = rects[b]
|
241 |
centre_of_A = [rectA[0] + (rectA[2] - rectA[0]) / 2, rectA[1] + (rectA[3] - rectA[1]) / 2]
|
242 |
centre_of_B = [rectB[0] + (rectB[2] - rectB[0]) / 2, rectB[1] + (rectB[3] - rectB[1]) / 2]
|
|
|
|
|
243 |
if np.allclose(np.array(centre_of_A), np.array(centre_of_B)):
|
244 |
-
return box(*rectA).area >
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
263 |
|
264 |
def get_distance(rectA, rectB):
|
265 |
return box(rectA[0], rectA[1], rectA[2], rectA[3]).distance(box(rectB[0], rectB[1], rectB[2], rectB[3]))
|
|
|
240 |
rectB = rects[b]
|
241 |
centre_of_A = [rectA[0] + (rectA[2] - rectA[0]) / 2, rectA[1] + (rectA[3] - rectA[1]) / 2]
|
242 |
centre_of_B = [rectB[0] + (rectB[2] - rectB[0]) / 2, rectB[1] + (rectB[3] - rectB[1]) / 2]
|
243 |
+
|
244 |
+
# Change starting preference to favor left-to-right
|
245 |
if np.allclose(np.array(centre_of_A), np.array(centre_of_B)):
|
246 |
+
return box(*rectA).area > box(*rectB).area
|
247 |
+
|
248 |
+
# Prefer strictly left-of to strictly right-of
|
249 |
+
# This prioritizes left-to-right spatial relationship checks
|
250 |
+
if is_strictly_left_of(rectA, rectB) and not is_strictly_below(rectA, rectB):
|
251 |
+
return True
|
252 |
+
if is_strictly_left_of(rectB, rectA) and not is_strictly_below(rectB, rectA):
|
253 |
+
return False
|
254 |
+
|
255 |
+
# Rest of the conditions (vertical directionality) remain the same
|
256 |
+
if is_strictly_above(rectA, rectB) and not is_strictly_left_of(rectA, rectB):
|
257 |
+
return True
|
258 |
+
if is_strictly_above(rectB, rectA) and not is_strictly_left_of(rectB, rectA):
|
259 |
+
return False
|
260 |
+
if is_strictly_below(rectA, rectB) and is_strictly_right_of(rectA, rectB):
|
261 |
+
return use_cuts_to_determine_edge_from_a_to_b(a, b, rects)
|
262 |
+
if is_strictly_below(rectB, rectA) and is_strictly_right_of(rectB, rectA):
|
263 |
+
return use_cuts_to_determine_edge_from_a_to_b(a, b, rects)
|
264 |
+
|
265 |
+
# Erosion as a fallback if intersecting
|
266 |
+
copy_A = erode_rectangle(rectA, 0.05)
|
267 |
+
copy_B = erode_rectangle(rectB, 0.05)
|
268 |
+
return box(*copy_A).area > box(*copy_B).area
|
269 |
|
270 |
def get_distance(rectA, rectB):
|
271 |
return box(rectA[0], rectA[1], rectA[2], rectA[3]).distance(box(rectB[0], rectB[1], rectB[2], rectB[3]))
|