Skip to content

Commit ec6badf

Browse files
fix: address pre-commit issues
1 parent bef1cc7 commit ec6badf

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

geometry/graham_scan.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def consecutive_orientation(self, point_a: Point, point_b: Point) -> float:
9898
>>> Point(0, 0).consecutive_orientation(Point(1, 0), Point(2, 0))
9999
0.0
100100
"""
101-
return (point_a.x - self.x) * (point_b.y - point_a.y) - (point_a.y - self.y) * (
102-
point_b.x - point_a.x
103-
)
101+
return (point_a.x - self.x) * (point_b.y - point_a.y) - (
102+
point_a.y - self.y
103+
) * (point_b.x - point_a.x)
104104

105105

106106
def graham_scan(points: Sequence[Point]) -> list[Point]:
@@ -148,7 +148,7 @@ def graham_scan(points: Sequence[Point]) -> list[Point]:
148148
# Edge case where all points are the same
149149
return []
150150

151-
def polar_angle_key(point: Point) -> tuple[float, float]:
151+
def polar_angle_key(point: Point) -> tuple[float, float, float]:
152152
"""
153153
Key function for sorting points by polar angle relative to min_point.
154154
@@ -166,7 +166,7 @@ def polar_angle_key(point: Point) -> tuple[float, float]:
166166
return (dx, dy, -distance) # Negative distance to sort farther points first
167167

168168
# Sort by polar angle using a comparison based on cross product
169-
def compare_points(point_a: Point, point_b: Point) -> float:
169+
def compare_points(point_a: Point, point_b: Point) -> int:
170170
"""Compare two points by polar angle relative to min_point."""
171171
orientation = min_point.consecutive_orientation(point_a, point_b)
172172
if orientation < 0.0:
@@ -177,7 +177,12 @@ def compare_points(point_a: Point, point_b: Point) -> float:
177177
# Collinear: farther point should come first
178178
dist_a = min_point.euclidean_distance(point_a)
179179
dist_b = min_point.euclidean_distance(point_b)
180-
return -1 if dist_b < dist_a else (1 if dist_b > dist_a else 0)
180+
if dist_b < dist_a:
181+
return -1
182+
elif dist_b > dist_a:
183+
return 1
184+
else:
185+
return 0
181186

182187
from functools import cmp_to_key
183188

geometry/tests/test_graham_scan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Tests for the Graham scan convex hull algorithm.
33
"""
44

5-
from graham_scan import Point, graham_scan
5+
from geometry.graham_scan import Point, graham_scan
66

77

88
def test_empty_points() -> None:

0 commit comments

Comments
 (0)