diff --git a/cadquery/selectors.py b/cadquery/selectors.py index 0fe1f76..14fdce2 100644 --- a/cadquery/selectors.py +++ b/cadquery/selectors.py @@ -325,29 +325,12 @@ class DirectionMinMaxSelector(Selector): class DirectionNthSelector(ParallelDirSelector): """ - Selects objects closest or farthest in the specified direction - Used for faces, points, and edges + Selects nth object parallel (or normal) to the specified direction + Used for faces and edges Applicability: - All object types. for a vertex, its point is used. for all other kinds - of objects, the center of mass of the object is used. - - You can use the string shortcuts >(X|Y|Z) or <(X|Y|Z) if you want to - select based on a cardinal direction. - - For example this:: - - CQ(aCube).faces ( DirectionMinMaxSelector((0,0,1),True ) - - Means to select the face having the center of mass farthest in the positive z direction, - and is the same as: - - CQ(aCube).faces( ">Z" ) - - Future Enhancements: - provide a nicer way to select in arbitrary directions. IE, a bit more code could - allow '>(0,0,1)' to work. - + Linear Edges + Planar Faces """ def __init__(self, vector, n, directionMax=True, tolerance=0.0001): self.direction = vector diff --git a/tests/TestCQSelectors.py b/tests/TestCQSelectors.py index 7843b12..05f9314 100644 --- a/tests/TestCQSelectors.py +++ b/tests/TestCQSelectors.py @@ -174,6 +174,10 @@ class TestCQSelectors(BaseTest): val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),1)).val() self.assertAlmostEqual(val.Center().x,-1.5) + #2nd face with inversed selection vector + val = c.faces(selectors.DirectionNthSelector(Vector(-1,0,0),1)).val() + self.assertAlmostEqual(val.Center().x,1.5) + #2nd last face val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),-2)).val() self.assertAlmostEqual(val.Center().x,1.5) @@ -182,7 +186,7 @@ class TestCQSelectors(BaseTest): val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),-1)).val() self.assertAlmostEqual(val.Center().x,2.5) - #check if the selected face if normal to given Vector + #check if the selected face if normal to the specified Vector self.assertAlmostEqual(val.normalAt().cross(Vector(1,0,0)).Length,0.0) def testNearestTo(self):