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
| 59 | |
| 60 | |
| 61 | class 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 | |
| 89 | class NearestToShapeSelector(Selector): |
no outgoing calls