|
15 | 15 |
|
16 | 16 | from typing import Iterable, List, Set, Union
|
17 | 17 |
|
| 18 | + |
18 | 19 | class Point:
|
19 | 20 | """
|
20 | 21 | Defines a 2-d point for use by all convex-hull algorithms.
|
@@ -82,7 +83,9 @@ def __hash__(self):
|
82 | 83 | return hash(self.x)
|
83 | 84 |
|
84 | 85 |
|
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]: |
86 | 89 | """
|
87 | 90 | constructs a list of points from an array-like object of numbers
|
88 | 91 |
|
@@ -111,7 +114,7 @@ def _construct_points(list_of_tuples: Union[List[Point], List[List[float]], Iter
|
111 | 114 | []
|
112 | 115 | """
|
113 | 116 |
|
114 |
| - points = [] |
| 117 | + points: List[Point] = [] |
115 | 118 | if list_of_tuples:
|
116 | 119 | for p in list_of_tuples:
|
117 | 120 | if isinstance(p, Point):
|
@@ -169,10 +172,15 @@ def _validate_input(points: Union[List[Point], List[List[float]]]) -> List[Point
|
169 | 172 | ValueError: Expecting an iterable object but got an non-iterable type 1
|
170 | 173 | """
|
171 | 174 |
|
| 175 | + if not hasattr(points, "__iter__"): |
| 176 | + raise ValueError( |
| 177 | + f"Expecting an iterable object but got an non-iterable type {points}" |
| 178 | + ) |
| 179 | + |
172 | 180 | if not points:
|
173 | 181 | raise ValueError(f"Expecting a list of points but got {points}")
|
174 | 182 |
|
175 |
| - return _construct_points(points) |
| 183 | + return _construct_points(points) |
176 | 184 |
|
177 | 185 |
|
178 | 186 | def _det(a: Point, b: Point, c: Point) -> float:
|
@@ -353,7 +361,9 @@ def convex_hull_recursive(points: List[Point]) -> List[Point]:
|
353 | 361 | return sorted(convex_set)
|
354 | 362 |
|
355 | 363 |
|
356 |
| -def _construct_hull(points: List[Point], left: Point, right: Point, convex_set: Set[Point]) -> None: |
| 364 | +def _construct_hull( |
| 365 | + points: List[Point], left: Point, right: Point, convex_set: Set[Point] |
| 366 | +) -> None: |
357 | 367 | """
|
358 | 368 |
|
359 | 369 | Parameters
|
|
0 commit comments