Skip to content

Commit 7162412

Browse files
author
Simon Lammer
committed
Fix build errors
1 parent 3a0316f commit 7162412

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

Diff for: divide_and_conquer/convex_hull.py

+25-16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from typing import Iterable, List, Set, Union
1717

18+
1819
class Point:
1920
"""
2021
Defines a 2-d point for use by all convex-hull algorithms.
@@ -82,7 +83,9 @@ def __hash__(self):
8283
return hash(self.x)
8384

8485

85-
def _construct_points(list_of_tuples: Union[List[Point], List[List[float]], Iterable[List[float]]]) -> List[Point]:
86+
def _construct_points(
87+
list_of_tuples: Union[List[Point], List[List[float]], Iterable[List[float]]]
88+
) -> List[Point]:
8689
"""
8790
constructs a list of points from an array-like object of numbers
8891
@@ -111,19 +114,18 @@ def _construct_points(list_of_tuples: Union[List[Point], List[List[float]], Iter
111114
[]
112115
"""
113116

114-
points = []
115-
if list_of_tuples:
116-
for p in list_of_tuples:
117-
if isinstance(p, Point):
118-
points.append(p)
119-
else:
120-
try:
121-
points.append(Point(p[0], p[1]))
122-
except (IndexError, TypeError):
123-
print(
124-
f"Ignoring deformed point {p}. All points"
125-
" must have at least 2 coordinates."
126-
)
117+
points: List[Point] = []
118+
for p in list_of_tuples:
119+
if isinstance(p, Point):
120+
points.append(p)
121+
else:
122+
try:
123+
points.append(Point(p[0], p[1]))
124+
except (IndexError, TypeError):
125+
print(
126+
f"Ignoring deformed point {p}. All points"
127+
" must have at least 2 coordinates."
128+
)
127129
return points
128130

129131

@@ -169,10 +171,15 @@ def _validate_input(points: Union[List[Point], List[List[float]]]) -> List[Point
169171
ValueError: Expecting an iterable object but got an non-iterable type 1
170172
"""
171173

174+
if not hasattr(points, "__iter__"):
175+
raise ValueError(
176+
f"Expecting an iterable object but got an non-iterable type {points}"
177+
)
178+
172179
if not points:
173180
raise ValueError(f"Expecting a list of points but got {points}")
174181

175-
return _construct_points(points)
182+
return _construct_points(points)
176183

177184

178185
def _det(a: Point, b: Point, c: Point) -> float:
@@ -353,7 +360,9 @@ def convex_hull_recursive(points: List[Point]) -> List[Point]:
353360
return sorted(convex_set)
354361

355362

356-
def _construct_hull(points: List[Point], left: Point, right: Point, convex_set: Set[Point]) -> None:
363+
def _construct_hull(
364+
points: List[Point], left: Point, right: Point, convex_set: Set[Point]
365+
) -> None:
357366
"""
358367
359368
Parameters

0 commit comments

Comments
 (0)