MCPcopy
hub / github.com/CadQuery/cadquery / testSpline

Method testSpline

tests/test_cadquery.py:686–723  ·  view source on GitHub ↗

Tests construction of splines

(self)

Source from the content-addressed store, hash-verified

684 result.revolve()
685
686 def testSpline(self):
687 """
688 Tests construction of splines
689 """
690 pts = [(0, 0), (0, 1), (1, 2), (2, 4)]
691
692 # Spline path - just a smoke test
693 path = Workplane("XZ").spline(pts).val()
694
695 # Closed spline
696 path_closed = Workplane("XZ").spline(pts, periodic=True).val()
697 self.assertTrue(path_closed.IsClosed())
698
699 # attempt to build a valid face
700 w = Wire.assembleEdges([path_closed,])
701 f = Face.makeFromWires(w)
702 self.assertTrue(f.isValid())
703
704 # attempt to build an invalid face
705 w = Wire.assembleEdges([path,])
706 f = Face.makeFromWires(w)
707 self.assertFalse(f.isValid())
708
709 # Spline with explicit tangents
710 path_const = Workplane("XZ").spline(pts, tangents=((0, 1), (1, 0))).val()
711 self.assertFalse(path.tangentAt(0) == path_const.tangentAt(0))
712 self.assertFalse(path.tangentAt(1) == path_const.tangentAt(1))
713
714 # test include current
715 path1 = Workplane("XZ").spline(pts[1:], includeCurrent=True).val()
716 self.assertAlmostEqual(path.Length(), path1.Length())
717
718 # test tangents and offset plane
719 pts = [(0, 0), (-1, 1), (-2, 0), (-1, 0)]
720 tangents = [(0, 1), (1, 0)]
721
722 path2 = Workplane("XY", (0, 0, 10)).spline(pts, tangents=tangents)
723 self.assertAlmostEqual(path2.val().tangentAt(0).z, 0)
724
725 def testSplineWithMultipleTangents(self):
726 """

Callers

nothing calls this directly

Calls 9

WorkplaneClass · 0.85
IsClosedMethod · 0.80
assembleEdgesMethod · 0.80
isValidMethod · 0.80
valMethod · 0.45
splineMethod · 0.45
makeFromWiresMethod · 0.45
tangentAtMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected