From dac178cbc4ca6e0926c4f3c9be693384fcb0cb0f Mon Sep 17 00:00:00 2001 From: JasonChmn <jason.chemin@hotmail.fr> Date: Mon, 20 May 2019 15:47:20 +0200 Subject: [PATCH] Add binding python for conversion, test ok --- python/curves_python.cpp | 5 +++-- python/test/test.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/python/curves_python.cpp b/python/curves_python.cpp index f1e216d..71866ac 100644 --- a/python/curves_python.cpp +++ b/python/curves_python.cpp @@ -369,9 +369,10 @@ BOOST_PYTHON_MODULE(curves) ; /** END bernstein polynomial**/ - /** BEGIN Bezier to polynomial conversion**/ + /** BEGIN curves conversion**/ def("polynom_from_bezier", polynom_from_bezier<bezier3_t,polynomial_t>); - /** END Bezier to polynomial conversion**/ + def("bezier_from_hermite", bezier_from_hermite<cubic_hermite_spline_t,bezier3_t>); + /** END curves conversion**/ } diff --git a/python/test/test.py b/python/test/test.py index d44c4a6..fffafd4 100644 --- a/python/test/test.py +++ b/python/test/test.py @@ -9,7 +9,7 @@ from numpy.linalg import norm import unittest -from curves import bezier3, bezier6, curve_constraints, exact_cubic, cubic_hermite_spline, polynom_from_bezier, polynomial +from curves import bezier3, bezier6, curve_constraints, exact_cubic, cubic_hermite_spline, polynom_from_bezier, bezier_from_hermite, polynomial class TestCurves(unittest.TestCase): @@ -135,6 +135,18 @@ class TestCurves(unittest.TestCase): self.assertTrue (norm(a(0.3) - a_pol(0.3)) < __EPS) return + def test_bezier_from_cubic_hermite(self): + # converting cubic hermite to cubic bezier + __EPS = 1e-6 + points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() + tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() + time_points = matrix([0., 1.]).transpose() + a_hermite = cubic_hermite_spline(points, tangents, time_points) + + a_bezier = bezier_from_hermite(a_hermite) + self.assertTrue (norm(a_hermite(0.3) - a_bezier(0.3)) < __EPS) + return + def test_cubic_hermite_spline(self): points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() -- GitLab