Fixed holding tags unit tests.

This commit is contained in:
Markus Lampert 2017-01-22 19:12:06 -08:00
parent 33a3c5fcf0
commit 7805dce66e
2 changed files with 18 additions and 20 deletions

View File

@ -52,8 +52,8 @@ LOG_MODULE = 'PathDressupHoldingTags'
def debugEdge(edge, prefix, force = False): def debugEdge(edge, prefix, force = False):
if force or PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG: if force or PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG:
pf = edge.valueAt(edge.FirstParameter) pf = edge.valueAt(edge.FirstParameter)
pl = edge.valueAt(edge.LastParameter) pl = edge.valueAt(edge.LastParameter)
if type(edge.Curve) == Part.Line or type(edge.Curve) == Part.LineSegment: if type(edge.Curve) == Part.Line or type(edge.Curve) == Part.LineSegment:
print("%s %s((%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f))" % (prefix, type(edge.Curve), pf.x, pf.y, pf.z, pl.x, pl.y, pl.z)) print("%s %s((%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f))" % (prefix, type(edge.Curve), pf.x, pf.y, pf.z, pl.x, pl.y, pl.z))
else: else:
@ -221,8 +221,10 @@ class Tag:
angle = -PathGeom.getAngle(self.originAt(0)) * 180 / math.pi angle = -PathGeom.getAngle(self.originAt(0)) * 180 / math.pi
PathLog.debug("solid.rotate(%f)" % angle) PathLog.debug("solid.rotate(%f)" % angle)
self.solid.rotate(FreeCAD.Vector(0,0,0), FreeCAD.Vector(0,0,1), angle) self.solid.rotate(FreeCAD.Vector(0,0,0), FreeCAD.Vector(0,0,1), angle)
PathLog.debug("solid.translate(%s)" % self.originAt(z)) orig = self.originAt(z - 0.01 * self.actualHeight)
self.solid.translate(self.originAt(z - 0.01 * self.actualHeight)) PathLog.debug("solid.translate(%s)" % oric)
self.solid.translate(oric)
radius = min(self.radius, radius)
self.realRadius = radius self.realRadius = radius
if radius != 0: if radius != 0:
PathLog.debug("makeFillet(%.4f)" % radius) PathLog.debug("makeFillet(%.4f)" % radius)

View File

@ -37,45 +37,41 @@ class TestHoldingTags(PathTestBase):
"""Unit tests for the HoldingTags dressup.""" """Unit tests for the HoldingTags dressup."""
def test00(self): def test00(self):
"""Check Tag origin, serialization and de-serialization.""" """Check Tag origin."""
tag = Tag(77, 13, 4, 5, 90, True) tag = Tag(77, 13, 4, 5, 90, True)
self.assertCoincide(tag.originAt(3), Vector(77, 13, 3)) self.assertCoincide(tag.originAt(3), Vector(77, 13, 3))
s = tag.toString()
tagCopy = Tag.FromString(s)
self.assertEqual(tag.x, tagCopy.x)
self.assertEqual(tag.y, tagCopy.y)
self.assertEqual(tag.height, tagCopy.height)
self.assertEqual(tag.width, tagCopy.width)
self.assertEqual(tag.enabled, tagCopy.enabled)
def test01(self): def test01(self):
"""Verify solid for a 90 degree tag is a cylinder.""" """Verify solid for a 90 degree tag is a cylinder."""
tag = Tag(100, 200, 4, 5, 90, True) tag = Tag(100, 200, 4, 5, 90, 0, True)
tag.createSolidsAt(17, 0) tag.createSolidsAt(17, 0)
self.assertIsNotNone(tag.solid) self.assertIsNotNone(tag.solid)
self.assertCylinderAt(tag.solid, Vector(100, 200, 17), 2, 5) self.assertCylinderAt(tag.solid, Vector(100, 200, 17 - 5 * 0.01), 2, 5 * 1.01)
def test02(self): def test02(self):
"""Verify trapezoidal tag has a cone shape with a lid.""" """Verify trapezoidal tag has a cone shape with a lid."""
tag = Tag(0, 0, 18, 5, 45, True) tag = Tag(0, 0, 18, 5, 45, 0, True)
tag.createSolidsAt(0, 0) tag.createSolidsAt(0, 0)
self.assertIsNotNone(tag.solid) self.assertIsNotNone(tag.solid)
self.assertConeAt(tag.solid, Vector(0,0,0), 9, 4, 5) self.assertConeAt(tag.solid, Vector(0,0,-0.05), 9, 3.95, 5.05)
def test03(self): def test03(self):
"""Verify pointy cone shape of tag with pointy end if width, angle and height match up.""" """Verify pointy cone shape of tag with pointy end if width, angle and height match up."""
tag = Tag(0, 0, 10, 5, 45, True) tag = Tag(0, 0, 10, 5, 45, 0, True)
tag.createSolidsAt(0, 0) tag.createSolidsAt(0, 0)
self.assertIsNotNone(tag.solid) self.assertIsNotNone(tag.solid)
self.assertConeAt(tag.solid, Vector(0,0,0), 5, 0, 5) h = 5 * 1.01
self.assertConeAt(tag.solid, Vector(0,0,-h * 0.01), 5, 0, h)
def test04(self): def test04(self):
"""Verify height adjustment if tag isn't wide eough for angle.""" """Verify height adjustment if tag isn't wide eough for angle."""
tag = Tag(0, 0, 5, 17, 60, True) tag = Tag(0, 0, 5, 17, 60, 0, True)
tag.createSolidsAt(0, 0) tag.createSolidsAt(0, 0)
self.assertIsNotNone(tag.solid) self.assertIsNotNone(tag.solid)
self.assertConeAt(tag.solid, Vector(0,0,0), 2.5, 0, 2.5 * math.tan((60/180.0)*math.pi)) h = 2.5 * math.tan((60/180.0)*math.pi) * 1.01
print(h)
self.assertConeAt(tag.solid, Vector(0,0,-h * 0.01), 2.5, 0, h)