From f8989928a8247d27cc2a8261f1ead2e628ff0e30 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Tue, 16 Jun 2015 17:03:36 -0400 Subject: [PATCH] Next phase of cleaning up CQ.py. --- .coverage | Bin 7458 -> 7643 bytes cadquery/CQ.py | 6 ++-- tests/TestCadQuery.py | 69 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/.coverage b/.coverage index c551dc97b25709e683584dd60a2ebbe7303dbf42..b9068da9e624b33f1ffb445df2dab0ddb461085c 100644 GIT binary patch delta 1671 zcmX}rX|N7t9ES1k|NZc)NQ*WUr6z^6jmc8ybSULGr@K*s`|D(Y1qQlq#yFUd>u+j&J^nb+jCd0k$g zEAxiDF>lJ7^9T9E{88STKhB@zPxI&bi@Ysw&tKiqk|B(Nr`Or;Fz0 zCAE((wiIo|dE$IgB1**tqD-_E7mAJo(Mfa`UBqRgtGHZTA+8qJh#ulv(NpvheZ`HU zpBNwpib3LLF+|)VhKgZgxVTM>5VwmvL{W^c+TG$_ai16~#)xSVy1XO%o4N3%c4Te74yV=@v2xL7K%mU4Y61(5lh7~@s?Pw zA}hp7u}Z8KYsEWaomej_#d~6d*eKo?Tf|oJvG_!MCO#M2#Ft{b_*(1`JH;-sTl^$` z6Tgc+Vz1aI6dV}T3~B|31cwDj1xE*UgJQj)esFxyC^#uNC1@Np37Q7YgEND(g0q7b z!MQ=JpmoqDC<)4f_QAzLhad-?f=h$WLD%5&pj&Wd&^_o8TpL^$^bC3hy@Tt6K0)8$ zhTz6x&_5Uu3=9SZgM(Xwp~0|VcrYTkJ-D+fGZ-0+3hoNV1Y?77!2`kgU_$UvFfn*E zcr2I{JP|w9*MbGX>%p7Bl3;1DELa|_ z3RVYef_1_ApfY$jcrVxxYz#I9n}ZL7Ey31cZ}3;}cW{7_u{qEjWDYhpO)YbXscjB5 zhnpiz9dnc^);0A^eRG^?U>cc|%*o~y)5J70&CMC+OmmKDVa_!zO>0wPO3ekP%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G+p= zgp0!^;nFZUTox`5Q^FPD%J8f2fZ^BS>hPOzZI~LSh3R2NxIWAbv%>6fL%1>A6n+<) zVNRGEZV9)B+rsa|?O|S+AMOZuhP%RourRGG3X8)%%~4%?G#(F6gg=HS!=J)aVOe-4 zEDz6xKZg}zWmpwn2rq`0!pmWGcr~mE>%zaof5I2x%djPE4PS+?!?w^;=ur56p<|&_ zVY@=-!VZPD!Vd~N6}p^I=vwGj*tyWX(6i91uxp`rVb8*k3VRjyDfBPwTiCBKurR1F mxUhfWz{0_W9~Xueh8IQ@YGG7ibYaZWWnIr~ZJyEVvi}1{%#kzz diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 62fdbc9..653a5ce 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -1652,11 +1652,11 @@ class Workplane(CQ): if s: return s.BoundingBox().DiagonalLength * 5.0 else: - return 1000000 + return -1 def cutEach(self, fcn, useLocalCoords=False): """ - Evaluates the provided function at each point on the stack ( ie, eachpoint ) + Evaluates the provided function at each point on the stack (ie, eachpoint) and then cuts the result from the context solid. :param fcn: a function suitable for use in the eachpoint method: ie, that accepts a vector @@ -1968,7 +1968,7 @@ class Workplane(CQ): def combine(self): """ - Attempts to combine all of the items on the items on the stack into a single item. + Attempts to combine all of the items on the stack into a single item. WARNING: all of the items must be of the same type! :raises: ValueError if there are no items on the stack, or if they cannot be combined diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index ca93d38..6a1f586 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -185,17 +185,27 @@ class TestCadQuery(BaseTest): def testPointList(self): - "Tests adding points and using them" + """ + Tests adding points and using them + """ c = CQ(makeUnitCube()) - s = c.faces(">Z").workplane().pushPoints([(-0.3,0.3),(0.3,0.3),(0,0)]) - self.assertEqual(3,s.size()) + s = c.faces(">Z").workplane().pushPoints([(-0.3, 0.3), (0.3, 0.3), (0, 0)]) + self.assertEqual(3, s.size()) #TODO: is the ability to iterate over points with circle really worth it? #maybe we should just require using all() and a loop for this. the semantics and #possible combinations got too hard ( ie, .circle().circle() ) was really odd body = s.circle(0.05).cutThruAll() self.saveModel(body) - self.assertEqual(9,body.faces().size()) + self.assertEqual(9, body.faces().size()) + + # Test the case when using eachpoint with only a blank workplane + def callback_fn(pnt): + self.assertEqual((0.0, 0.0), (pnt.x, pnt.y)) + + r = Workplane('XY') + r.objects = [] + r.eachpoint(callback_fn) def testWorkplaneFromFace(self): @@ -260,7 +270,8 @@ class TestCadQuery(BaseTest): Test creating a solid using the revolve operation. :return: """ - #The dimensions of the model. These can be modified rather than changing the shape's code directly. + # The dimensions of the model. These can be modified rather than changing the + # shape's code directly. rectangle_width = 10.0 rectangle_length = 10.0 angle_degrees = 360.0 @@ -316,12 +327,14 @@ class TestCadQuery(BaseTest): Test creating a solid donut shape with square walls :return: """ - #The dimensions of the model. These can be modified rather than changing the shape's code directly. + # The dimensions of the model. These can be modified rather than changing the + # shape's code directly. rectangle_width = 10.0 rectangle_length = 10.0 angle_degrees = 360.0 - result = Workplane("XY").rect(rectangle_width, rectangle_length, True).revolve(angle_degrees, (20, 0), (20, 10)) + result = Workplane("XY").rect(rectangle_width, rectangle_length, True)\ + .revolve(angle_degrees, (20, 0), (20, 10)) self.assertEqual(4, result.faces().size()) self.assertEqual(4, result.vertices().size()) self.assertEqual(6, result.edges().size()) @@ -336,6 +349,24 @@ class TestCadQuery(BaseTest): self.assertEqual(2, result.vertices().size()) self.assertEqual(3, result.edges().size()) + def testTwistExtrude(self): + """ + Tests extrusion while twisting through an angle. + """ + profile = Workplane('XY').rect(10, 10) + r = profile.twistExtrude(10, 45, False) + + self.assertEqual(6, r.faces().size()) + + def testTwistExtrudeCombine(self): + """ + Tests extrusion while twisting through an angle, combining with other solids. + """ + profile = Workplane('XY').rect(10, 10) + r = profile.twistExtrude(10, 45) + + self.assertEqual(6, r.faces().size()) + def testRectArray(self): NUMX=3 NUMY=3 @@ -612,6 +643,20 @@ class TestCadQuery(BaseTest): r.vertices(selectors.NearestToPointSelector((0.0, 0.0, 0.0)))\ .first().val().Y)) + def testLargestDimension(self): + """ + Tests the largestDimension function when no solids are on the stack and when there are + """ + r = Workplane('XY').box(1, 1, 1) + dim = r.largestDimension() + + self.assertAlmostEqual(8.66025403784, dim) + + r = Workplane('XY') + dim = r.largestDimension() + + self.assertEqual(-1, dim) + def testOccBottle(self): """ Make the OCC bottle example. @@ -768,9 +813,17 @@ class TestCadQuery(BaseTest): (-1.0, -1.0), (0.0, 0.0), (1.0, 1.0) ] c.faces(">Z").workplane().pushPoints(pnts).cboreHole(0.1, 0.25, 0.25, 0.75) - self.assertEquals(18, c.faces().size() ) + self.assertEquals(18, c.faces().size()) self.saveModel(c) + # Tests the case where the depth of the cboreHole is not specified + c2 = CQ(makeCube(3.0)) + pnts = [ + (-1.0, -1.0), (0.0, 0.0), (1.0, 1.0) + ] + c2.faces(">Z").workplane().pushPoints(pnts).cboreHole(0.1, 0.25, 0.25) + self.assertEquals(15, c2.faces().size()) + def testCounterSinks(self): """ Tests countersinks