Added a test to ensure that finding the center of a compound works correctly.

This commit is contained in:
Jeremy Mack Wright 2015-09-17 19:13:05 -04:00
parent 23f1a0ea68
commit d6ec0ea6bd
2 changed files with 22 additions and 1 deletions

View File

@ -192,7 +192,6 @@ class Shape(object):
return Vector(self.wrapped.CenterOfMass)
elif len(self.Solids()) == 1:
return Vector(self.Solids()[0].wrapped.CenterOfMass)
elif len(self.Solids()) > 1:
return self.CombinedCenter(self.Solids())
elif isinstance(self.wrapped, FreeCADPart.Solid):

View File

@ -41,6 +41,28 @@ class TestCadObjects(BaseTest):
self.assertTupleAlmostEquals((1.0, 2.0, 3.0), e.Center().toTuple(), 3)
def testCompoundCenter(self):
"""
Tests whether or not a proper weighted center can be found for a compound
"""
def cylinders(self, radius, height):
def _cyl(pnt):
# Inner function to build a cylinder
return Solid.makeCylinder(radius, height, pnt)
# Combine all the cylinders into a single compound
r = self.eachpoint(_cyl, True).combineSolids()
return r
Workplane.cyl = cylinders
# Now test. here we want weird workplane to see if the objects are transformed right
s = Workplane("XY").rect(2.0, 3.0, forConstruction=True).vertices().cyl(0.25, 0.5)
self.assertEquals(4, len(s.val().Solids()))
self.assertTupleAlmostEquals((0.0, 0.0, 0.25), s.val().Center().toTuple(), 3)
def testDot(self):
v1 = Vector(2, 2, 2)
v2 = Vector(1, -1, 1)