@@ -87,7 +87,7 @@ def jarvis_march(points: list[Point]) -> list[Point]:
8787
8888 # Remove duplicate points to avoid infinite loops
8989 unique_points = list (set (points ))
90-
90+
9191 if len (unique_points ) <= 2 :
9292 return []
9393
@@ -102,7 +102,9 @@ def jarvis_march(points: list[Point]) -> list[Point]:
102102 ):
103103 left_point_idx = i
104104
105- convex_hull .append (Point (unique_points [left_point_idx ].x , unique_points [left_point_idx ].y ))
105+ convex_hull .append (
106+ Point (unique_points [left_point_idx ].x , unique_points [left_point_idx ].y )
107+ )
106108
107109 current_idx = left_point_idx
108110 while True :
@@ -111,12 +113,19 @@ def jarvis_march(points: list[Point]) -> list[Point]:
111113 # Make sure next_idx is not the same as current_idx (handle duplicates)
112114 while next_idx == current_idx :
113115 next_idx = (next_idx + 1 ) % len (unique_points )
114-
116+
115117 for i in range (len (unique_points )):
116118 # Skip the current point itself (handles duplicates)
117119 if i == current_idx :
118120 continue
119- if _cross_product (unique_points [current_idx ], unique_points [i ], unique_points [next_idx ]) > 0 :
121+ if (
122+ _cross_product (
123+ unique_points [current_idx ],
124+ unique_points [i ],
125+ unique_points [next_idx ],
126+ )
127+ > 0
128+ ):
120129 next_idx = i
121130
122131 if next_idx == left_point_idx :
@@ -135,9 +144,13 @@ def jarvis_march(points: list[Point]) -> list[Point]:
135144 convex_hull [last - 1 ], convex_hull [last ], unique_points [current_idx ]
136145 ):
137146 # Remove the last point from the hull
138- convex_hull [last ] = Point (unique_points [current_idx ].x , unique_points [current_idx ].y )
147+ convex_hull [last ] = Point (
148+ unique_points [current_idx ].x , unique_points [current_idx ].y
149+ )
139150 else :
140- convex_hull .append (Point (unique_points [current_idx ].x , unique_points [current_idx ].y ))
151+ convex_hull .append (
152+ Point (unique_points [current_idx ].x , unique_points [current_idx ].y )
153+ )
141154
142155 # Check for edge case: last point collinear with first and second-to-last
143156 if len (convex_hull ) <= 2 :
@@ -159,7 +172,7 @@ def jarvis_march(points: list[Point]) -> list[Point]:
159172 if abs (_cross_product (p1 , p2 , p3 )) > 1e-9 :
160173 has_turn = True
161174 break
162-
175+
163176 if not has_turn :
164177 return []
165178
0 commit comments