From 0dcccc351dc23fc875b8ebfd01933067d64ed413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Mon, 15 Feb 2021 21:18:09 +0100 Subject: [PATCH] tangentAt fix (#641) * tangentAt fix * Better testTangengAt * Change default to length * tests fix --- cadquery/occ_impl/shapes.py | 4 ++-- tests/test_cadquery.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 4e133d06..6fdc01c3 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -1117,7 +1117,7 @@ class Mixin1D(object): 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 @@ class Mixin1D(object): 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 ad0b103b..e992b1a9 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -3999,8 +3999,21 @@ class TestCadQuery(BaseTest): 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):