Return the nth object in the objectlist sorted by self.key and clustered if within self.tolerance.
(self, objectlist: Sequence[Shape])
| 299 | self.tolerance = tolerance |
| 300 | |
| 301 | def filter(self, objectlist: Sequence[Shape]) -> List[Shape]: |
| 302 | """ |
| 303 | Return the nth object in the objectlist sorted by self.key and |
| 304 | clustered if within self.tolerance. |
| 305 | """ |
| 306 | |
| 307 | if len(objectlist) == 0: |
| 308 | # nothing to filter |
| 309 | raise ValueError("Can not return the Nth element of an empty list") |
| 310 | |
| 311 | clustered = self.cluster(objectlist) |
| 312 | if not self.directionMax: |
| 313 | clustered.reverse() |
| 314 | try: |
| 315 | out = clustered[self.n] |
| 316 | except IndexError: |
| 317 | raise IndexError( |
| 318 | f"Attempted to access index {self.n} of a list with length {len(clustered)}" |
| 319 | ) |
| 320 | |
| 321 | return out |
| 322 | |
| 323 | @abstractmethod |
| 324 | def key(self, obj: Shape) -> float: |