From a9981b174e293ff8bf3b79034436d1bbbd90aa1a Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Wed, 1 Apr 2020 09:41:54 +0200
Subject: [PATCH] core/geometry: specialize converter for Quaternion

---
 include/eigenpy/quaternion.hpp | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/include/eigenpy/quaternion.hpp b/include/eigenpy/quaternion.hpp
index 6635d25d..fd231891 100644
--- a/include/eigenpy/quaternion.hpp
+++ b/include/eigenpy/quaternion.hpp
@@ -12,6 +12,49 @@
 
 #include "eigenpy/exception.hpp"
 
+namespace boost { namespace python { namespace converter {
+
+  /// \brief Template specialization of rvalue_from_python_data
+  template<typename Quaternion>
+  struct rvalue_from_python_data<Eigen::QuaternionBase<Quaternion> const &>
+  : rvalue_from_python_data_eigen<Quaternion const &>
+  {
+    RVALUE_FROM_PYTHON_DATA_INIT(Quaternion const &)
+  };
+
+  template <class Quaternion>
+  struct implicit<Quaternion, Eigen::QuaternionBase<Quaternion> >
+  {
+    typedef Quaternion Source;
+    typedef Eigen::QuaternionBase<Quaternion> Target;
+    
+    static void* convertible(PyObject* obj)
+    {
+      // Find a converter which can produce a Source instance from
+      // obj. The user has told us that Source can be converted to
+      // Target, and instantiating construct() below, ensures that
+      // at compile-time.
+      return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
+      ? obj : 0;
+    }
+    
+    static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
+    {
+      void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
+      
+      arg_from_python<Source> get_source(obj);
+      bool convertible = get_source.convertible();
+      BOOST_VERIFY(convertible);
+      
+      new (storage) Source(get_source());
+      
+      // record successful construction
+      data->convertible = storage;
+    }
+  };
+
+}}} // namespace boost::python::converter
+
 namespace eigenpy
 {
 
-- 
GitLab