MCPcopy
hub / github.com/CadQuery/cadquery / filter

Method filter

cadquery/selectors.py:301–321  ·  view source on GitHub ↗

Return the nth object in the objectlist sorted by self.key and clustered if within self.tolerance.

(self, objectlist: Sequence[Shape])

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 2

clusterMethod · 0.95
reverseMethod · 0.80

Tested by

no test coverage detected