commit
34d2e26369
|
@ -190,9 +190,10 @@ class Shape(object):
|
|||
# If there are no Solids, we're probably dealing with a Face or something similar
|
||||
if len(self.Solids()) == 0:
|
||||
return Vector(self.wrapped.CenterOfMass)
|
||||
else:
|
||||
# TODO: compute the weighted average instead of using the first solid
|
||||
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):
|
||||
return Vector(self.wrapped.CenterOfMass)
|
||||
else:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user