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

Class NearestToPointSelector

cadquery/selectors.py:61–86  ·  view source on GitHub ↗

Selects object nearest the provided point. If the object is a vertex or point, the distance is used. For other kinds of shapes, the center of mass is used to to compute which is closest. Applicability: All Types of Shapes Example:: CQ(aCube).vertices(NearestToPoin

Source from the content-addressed store, hash-verified

59
60
61class NearestToPointSelector(Selector):
62 """
63 Selects object nearest the provided point.
64
65 If the object is a vertex or point, the distance
66 is used. For other kinds of shapes, the center of mass
67 is used to to compute which is closest.
68
69 Applicability: All Types of Shapes
70
71 Example::
72
73 CQ(aCube).vertices(NearestToPointSelector((0, 1, 0)))
74
75 returns the vertex of the unit cube closest to the point x=0,y=1,z=0
76
77 """
78
79 def __init__(self, pnt):
80 self.pnt = pnt
81
82 def filter(self, objectList: Sequence[Shape]):
83 def dist(tShape):
84 return tShape.Center().sub(Vector(*self.pnt)).Length
85
86 return [min(objectList, key=dist)]
87
88
89class NearestToShapeSelector(Selector):

Callers 1

test_single_ent_selectorFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_single_ent_selectorFunction · 0.72