Test fixes

This commit is contained in:
adam-urbanczyk
2020-06-17 21:04:54 +02:00
parent d14c09b96d
commit 191d78d558
2 changed files with 18 additions and 22 deletions

View File

@ -210,12 +210,11 @@ class TestCadObjects(BaseTest):
""" """
def cylinders(self, radius, height): def cylinders(self, radius, height):
def _cyl(pnt):
# Inner function to build a cylinder c = Solid.makeCylinder(radius, height, Vector())
return Solid.makeCylinder(radius, height, pnt)
# Combine all the cylinders into a single compound # Combine all the cylinders into a single compound
r = self.eachpoint(_cyl, True).combineSolids() r = self.eachpoint(lambda loc: c.located(loc), True).combineSolids()
return r return r

View File

@ -125,15 +125,11 @@ class TestCadQuery(BaseTest):
def makeCubes(self, length): def makeCubes(self, length):
# self refers to the CQ or Workplane object # self refers to the CQ or Workplane object
# inner method that creates a cube # create the solid
def _singleCube(pnt): s = Solid.makeBox(length, length, length, Vector(0, 0, 0))
# pnt is a location in local coordinates
# since we're using eachpoint with useLocalCoordinates=True
return Solid.makeBox(length, length, length, pnt)
# use CQ utility method to iterate over the stack, call our # use CQ utility method to iterate over the stack an position the cubes
# method, and convert to/from local coordinates. return self.eachpoint(lambda loc: s.located(loc), True)
return self.eachpoint(_singleCube, True)
# link the plugin in # link the plugin in
Workplane.makeCubes = makeCubes Workplane.makeCubes = makeCubes
@ -161,12 +157,12 @@ class TestCadQuery(BaseTest):
""" """
def cylinders(self, radius, height): def cylinders(self, radius, height):
def _cyl(pnt):
# inner function to build a cylinder # construct a cylinder at (0,0,0)
return Solid.makeCylinder(radius, height, pnt) c = Solid.makeCylinder(radius, height, Vector(0, 0, 0))
# combine all the cylinders into a single compound # combine all the cylinders into a single compound
r = self.eachpoint(_cyl, True).combineSolids() r = self.eachpoint(lambda loc: c.located(loc), True).combineSolids()
return r return r
Workplane.cyl = cylinders Workplane.cyl = cylinders
@ -190,20 +186,19 @@ class TestCadQuery(BaseTest):
""" """
def rPoly(self, nSides, diameter): def rPoly(self, nSides, diameter):
def _makePolygon(center): def _makePolygon(loc):
# pnt is a vector in local coordinates # pnt is a vector in local coordinates
angle = 2.0 * math.pi / nSides angle = 2.0 * math.pi / nSides
pnts = [] pnts = []
for i in range(nSides + 1): for i in range(nSides + 1):
pnts.append( pnts.append(
center Vector(
+ Vector(
(diameter / 2.0 * math.cos(angle * i)), (diameter / 2.0 * math.cos(angle * i)),
(diameter / 2.0 * math.sin(angle * i)), (diameter / 2.0 * math.sin(angle * i)),
0, 0,
) )
) )
return Wire.makePolygon(pnts) return Wire.makePolygon(pnts).located(loc)
return self.eachpoint(_makePolygon, True) return self.eachpoint(_makePolygon, True)
@ -240,8 +235,10 @@ class TestCadQuery(BaseTest):
self.assertEqual(9, body.faces().size()) self.assertEqual(9, body.faces().size())
# Test the case when using eachpoint with only a blank workplane # Test the case when using eachpoint with only a blank workplane
def callback_fn(pnt): def callback_fn(loc):
self.assertEqual((0.0, 0.0), (pnt.x, pnt.y)) self.assertEqual(
Vector(0, 0, 0), Vector(loc.wrapped.Transformation().TranslationPart())
)
r = Workplane("XY") r = Workplane("XY")
r.objects = [] r.objects = []