Updated docstring for DirectionNthSelector and extended the related test-case
This commit is contained in:
parent
6678d3f546
commit
9df0e39133
|
@ -325,29 +325,12 @@ class DirectionMinMaxSelector(Selector):
|
||||||
|
|
||||||
class DirectionNthSelector(ParallelDirSelector):
|
class DirectionNthSelector(ParallelDirSelector):
|
||||||
"""
|
"""
|
||||||
Selects objects closest or farthest in the specified direction
|
Selects nth object parallel (or normal) to the specified direction
|
||||||
Used for faces, points, and edges
|
Used for faces and edges
|
||||||
|
|
||||||
Applicability:
|
Applicability:
|
||||||
All object types. for a vertex, its point is used. for all other kinds
|
Linear Edges
|
||||||
of objects, the center of mass of the object is used.
|
Planar Faces
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, vector, n, directionMax=True, tolerance=0.0001):
|
def __init__(self, vector, n, directionMax=True, tolerance=0.0001):
|
||||||
self.direction = vector
|
self.direction = vector
|
||||||
|
|
|
@ -174,6 +174,10 @@ class TestCQSelectors(BaseTest):
|
||||||
val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),1)).val()
|
val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),1)).val()
|
||||||
self.assertAlmostEqual(val.Center().x,-1.5)
|
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
|
#2nd last face
|
||||||
val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),-2)).val()
|
val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),-2)).val()
|
||||||
self.assertAlmostEqual(val.Center().x,1.5)
|
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()
|
val = c.faces(selectors.DirectionNthSelector(Vector(1,0,0),-1)).val()
|
||||||
self.assertAlmostEqual(val.Center().x,2.5)
|
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)
|
self.assertAlmostEqual(val.normalAt().cross(Vector(1,0,0)).Length,0.0)
|
||||||
|
|
||||||
def testNearestTo(self):
|
def testNearestTo(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user