diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 4e133d06b..6fdc01c3d 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -1117,7 +1117,7 @@ def paramAt(self: Mixin1DProtocol, d: float) -> float: def tangentAt( self: Mixin1DProtocol, locationParam: float = 0.5, - mode: Literal["length", "parameter"] = "parameter", + mode: Literal["length", "parameter"] = "length", ) -> Vector: """ Compute tangent vector at the specified location. @@ -1137,7 +1137,7 @@ def tangentAt( else: param = locationParam - curve.D1(self.paramAt(param), tmp, res) + curve.D1(param, tmp, res) return Vector(gp_Dir(res)) diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index ad0b103bc..e992b1a96 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -3999,8 +3999,21 @@ def testTangengAt(self): path = Workplane("XZ").spline(pts, tangents=((0, 1), (1, 0))).val() - self.assertTrue(path.tangentAt(0.5) == path.tangentAt(0.5)) - self.assertFalse(path.tangentAt(0.5) == path.tangentAt(0.5, mode="length")) + self.assertTrue( + path.tangentAt(0.0, mode="parameter") == path.tangentAt(0.0, mode="length") + ) + self.assertFalse( + path.tangentAt(0.5, mode="parameter") == path.tangentAt(0.5, mode="length") + ) + + arc = Workplane().radiusArc((2, 0), 1).val() + + self.assertTupleAlmostEquals( + arc.tangentAt(math.pi / 2, "parameter").toTuple(), (1, 0, 0), 6 + ) + self.assertTupleAlmostEquals( + arc.tangentAt(0.5, "length").toTuple(), (1, 0, 0), 6 + ) def testEnd(self):