From 89b109b9566462a02dfe879b714d478d0c246acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Yavuz=20=C3=96ZDERYA?= Date: Wed, 16 Sep 2015 22:55:07 +0300 Subject: [PATCH 1/3] min/max selector will return all objects within a tolerance --- cadquery/selectors.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cadquery/selectors.py b/cadquery/selectors.py index ada9bd5..be07d7b 100644 --- a/cadquery/selectors.py +++ b/cadquery/selectors.py @@ -291,13 +291,13 @@ class DirectionMinMaxSelector(Selector): allow '>(0,0,1)' to work. """ - def __init__(self,vector,directionMax=True): + def __init__(self, vector, directionMax=True, tolerance=0.0001): self.vector = vector self.max = max self.directionMax = directionMax + self.TOLERANCE = tolerance def filter(self,objectList): - #then sort by distance from origin, along direction specified def distance(tShape): return tShape.Center().dot(self.vector) #if tShape.ShapeType == 'Vertex': @@ -306,10 +306,14 @@ class DirectionMinMaxSelector(Selector): # pnt = tShape.Center() #return pnt.dot(self.vector) + # find out the max/min distance if self.directionMax: - return [ max(objectList,key=distance) ] + d = max(map(distance, objectList)) else: - return [ min(objectList,key=distance) ] + d = min(map(distance, objectList)) + + # return all objects at the max/min distance (within a tolerance) + return filter(lambda o: abs(d - distance(o)) < self.TOLERANCE, objectList) class BinarySelector(Selector): """ From 562e44c01d852e25a0b69b7885d0630b77bec01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Yavuz=20=C3=96ZDERYA?= Date: Thu, 17 Sep 2015 07:41:52 +0300 Subject: [PATCH 2/3] fail to prevent creating random workplanes --- cadquery/CQ.py | 4 ++++ tests/TestCadQuery.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 7504b16..cc03f8b 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -298,6 +298,10 @@ class CQ(object): For now you can work around by creating a workplane and then offsetting the center afterwards. """ + if len(self.objects) > 1: + raise ValueError("Workplane cannot be created if more than" + " 1 object is selected.") + obj = self.objects[0] def _computeXdir(normal): diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index 975feca..e58b594 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -442,7 +442,7 @@ class TestCadQuery(BaseTest): c = CQ( makeUnitCube()) #the cube is the context solid self.assertEqual(6,c.faces().size()) #cube has six faces - r = c.faces().workplane().circle(0.125).extrude(0.5,True) #make a boss, not updating the original + r = c.faces('>Z').workplane().circle(0.125).extrude(0.5,True) #make a boss, not updating the original self.assertEqual(8,r.faces().size()) #just the boss faces self.assertEqual(8,c.faces().size()) #original is modified too From 6551218d55794a180ec3ef5e2c10ec2629573e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Yavuz=20=C3=96ZDERYA?= Date: Thu, 17 Sep 2015 07:46:46 +0300 Subject: [PATCH 3/3] add test for multiple object at min/max selection --- tests/TestCQSelectors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/TestCQSelectors.py b/tests/TestCQSelectors.py index 53f5780..f90e14b 100644 --- a/tests/TestCQSelectors.py +++ b/tests/TestCQSelectors.py @@ -147,6 +147,10 @@ class TestCQSelectors(BaseTest): for v in c.faces(">Z").vertices().vals(): self.assertAlmostEqual(1.0,v.Z,3) + # test the case of multiple objects at the same distance + el = c.edges("