validates an input instance before a convex-hull algorithms uses it Parameters --------- points: array-like, the 2d points to validate before using with a convex-hull algorithm. The elements of points must be either lists, tuples or Points. Returns ------- poin
(points: list[Point] | list[list[float]])
| 133 | |
| 134 | |
| 135 | def _validate_input(points: list[Point] | list[list[float]]) -> list[Point]: |
| 136 | """ |
| 137 | validates an input instance before a convex-hull algorithms uses it |
| 138 | |
| 139 | Parameters |
| 140 | --------- |
| 141 | points: array-like, the 2d points to validate before using with |
| 142 | a convex-hull algorithm. The elements of points must be either lists, tuples or |
| 143 | Points. |
| 144 | |
| 145 | Returns |
| 146 | ------- |
| 147 | points: array_like, an iterable of all well-defined Points constructed passed in. |
| 148 | |
| 149 | |
| 150 | Exception |
| 151 | --------- |
| 152 | ValueError: if points is empty or None, or if a wrong data structure like a scalar |
| 153 | is passed |
| 154 | |
| 155 | TypeError: if an iterable but non-indexable object (eg. dictionary) is passed. |
| 156 | The exception to this a set which we'll convert to a list before using |
| 157 | |
| 158 | |
| 159 | Examples |
| 160 | ------- |
| 161 | >>> _validate_input([[1, 2]]) |
| 162 | [(1.0, 2.0)] |
| 163 | >>> _validate_input([(1, 2)]) |
| 164 | [(1.0, 2.0)] |
| 165 | >>> _validate_input([Point(2, 1), Point(-1, 2)]) |
| 166 | [(2.0, 1.0), (-1.0, 2.0)] |
| 167 | >>> _validate_input([]) |
| 168 | Traceback (most recent call last): |
| 169 | ... |
| 170 | ValueError: Expecting a list of points but got [] |
| 171 | >>> _validate_input(1) |
| 172 | Traceback (most recent call last): |
| 173 | ... |
| 174 | ValueError: Expecting an iterable object but got an non-iterable type 1 |
| 175 | """ |
| 176 | |
| 177 | if not hasattr(points, "__iter__"): |
| 178 | msg = f"Expecting an iterable object but got an non-iterable type {points}" |
| 179 | raise ValueError(msg) |
| 180 | |
| 181 | if not points: |
| 182 | msg = f"Expecting a list of points but got {points}" |
| 183 | raise ValueError(msg) |
| 184 | |
| 185 | return _construct_points(points) |
| 186 | |
| 187 | |
| 188 | def _det(a: Point, b: Point, c: Point) -> float: |
no test coverage detected