Next phase of cleaning up CQ.py.

This commit is contained in:
Jeremy Wright 2015-06-16 17:03:36 -04:00
parent 7f0ef93868
commit f8989928a8
3 changed files with 64 additions and 11 deletions

BIN
.coverage

Binary file not shown.

View File

@ -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

View File

@ -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