From d950da501ec8c9ad117b5e493ee4ece48dfd55d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Mon, 15 Feb 2021 07:57:17 +0100 Subject: [PATCH 1/4] tangentAt fix --- cadquery/occ_impl/shapes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 4e133d06b..98204766c 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -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)) From 186ee0843d498ba3141655ea07aaf3e36bfa68a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Mon, 15 Feb 2021 08:12:54 +0100 Subject: [PATCH 2/4] Better testTangengAt --- tests/test_cadquery.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index ad0b103bc..cbfd7b44c 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -4002,6 +4002,11 @@ def testTangengAt(self): self.assertTrue(path.tangentAt(0.5) == path.tangentAt(0.5)) self.assertFalse(path.tangentAt(0.5) == path.tangentAt(0.5, mode="length")) + arc = Workplane().radiusArc((2, 0), 1).val() + + self.assertTupleAlmostEquals(arc.tangentAt(math.pi/2).toTuple(), (1, 0, 0), 6) + self.assertTupleAlmostEquals(arc.tangentAt(0.5, "length").toTuple(), (1, 0, 0), 6) + def testEnd(self): with self.assertRaises(ValueError): From a835158e77e4ed66d9e062a985a22eb8d50cb9b3 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Mon, 15 Feb 2021 08:31:52 +0100 Subject: [PATCH 3/4] Change default to length --- cadquery/occ_impl/shapes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 98204766c..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. From ed41810bc03249c1aa69ad373d16d58cca2f4eec Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Mon, 15 Feb 2021 08:32:09 +0100 Subject: [PATCH 4/4] tests fix --- tests/test_cadquery.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index cbfd7b44c..e992b1a96 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -3999,13 +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).toTuple(), (1, 0, 0), 6) - self.assertTupleAlmostEquals(arc.tangentAt(0.5, "length").toTuple(), (1, 0, 0), 6) + 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):