@@ -101,22 +101,24 @@ def closest_pair_of_points_sqr(points_sorted_on_x, points_sorted_on_y, points_co
101
101
# recursion
102
102
mid = points_counts // 2
103
103
closest_in_left = closest_pair_of_points_sqr (
104
- points_sorted_on_x , points_sorted_on_y [:mid ], mid
105
- )
106
- closest_in_right = closest_pair_of_points_sqr (
107
- points_sorted_on_y , points_sorted_on_y [mid :], points_counts - mid
108
- )
109
- closest_pair_dis = min (closest_in_left , closest_in_right )
104
+ points_sorted_on_x , points_sorted_on_y [:mid ], mid
105
+ )
106
+ closest_in_right = closest_pair_of_points_sqr (
107
+ points_sorted_on_x , points_sorted_on_y [mid :], points_counts - mid
108
+ )
109
+ closest_pair_dis = min (closest_in_left , closest_in_right )
110
+
110
111
111
112
"""
112
113
cross_strip contains the points, whose Xcoords are at a
113
114
distance(< closest_pair_dis) from mid's Xcoord
114
115
"""
116
+ cross_strip = []
117
+ mid_x = points_sorted_on_x [mid ][0 ] # x-coordinate of the middle point
118
+ for point in points_sorted_on_x :
119
+ if abs (point [0 ] - mid_x ) < closest_pair_dis :
120
+ cross_strip .append (point )
115
121
116
- cross_strip = []
117
- for point in points_sorted_on_x :
118
- if abs (point [0 ] - points_sorted_on_x [mid ][0 ]) < closest_pair_dis :
119
- cross_strip .append (point )
120
122
121
123
closest_in_strip = dis_between_closest_in_strip (
122
124
cross_strip , len (cross_strip ), closest_pair_dis
0 commit comments