NicFromLM commited on
Commit
fb61075
·
verified ·
1 Parent(s): 03a584c

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +25 -19
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 > (box(*rectB)).area
245
- copy_A = [rectA[0], rectA[1], rectA[2], rectA[3]]
246
- copy_B = [rectB[0], rectB[1], rectB[2], rectB[3]]
247
- while True:
248
- if is_strictly_above(copy_A, copy_B) and not is_strictly_left_of(copy_A, copy_B):
249
- return 1
250
- if is_strictly_above(copy_B, copy_A) and not is_strictly_left_of(copy_B, copy_A):
251
- return 0
252
- if is_strictly_right_of(copy_A, copy_B) and not is_strictly_below(copy_A, copy_B):
253
- return 1
254
- if is_strictly_right_of(copy_B, copy_A) and not is_strictly_below(copy_B, copy_A):
255
- return 0
256
- if is_strictly_below(copy_A, copy_B) and is_strictly_right_of(copy_A, copy_B):
257
- return use_cuts_to_determine_edge_from_a_to_b(a, b, rects)
258
- if is_strictly_below(copy_B, copy_A) and is_strictly_right_of(copy_B, copy_A):
259
- return use_cuts_to_determine_edge_from_a_to_b(a, b, rects)
260
- # otherwise they intersect
261
- copy_A = erode_rectangle(copy_A, 0.05)
262
- copy_B = erode_rectangle(copy_B, 0.05)
 
 
 
 
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]))