diff --git a/include/glaze/ext/eigen.hpp b/include/glaze/ext/eigen.hpp index 7e4daa008c..02a21bb908 100644 --- a/include/glaze/ext/eigen.hpp +++ b/include/glaze/ext/eigen.hpp @@ -195,6 +195,33 @@ namespace glz GLZ_MATCH_CLOSE_BRACKET; } }; + + template + struct from> + { + template + static void op(auto& value, is_context auto&& ctx, auto&& it, auto&& end) + { + constexpr auto size = + Mode == Eigen::TransformTraits::AffineCompact ? (Dim + 1) * Dim : (Dim + 1) * (Dim + 1); + std::span view(value.data(), size); + detail::read::op(view, ctx, it, end); + } + }; + + template + struct to> + { + template + static void op(auto&& value, is_context auto&& ctx, auto&& b, auto&& ix) + { + constexpr auto size = + Mode == Eigen::TransformTraits::AffineCompact ? (Dim + 1) * Dim : (Dim + 1) * (Dim + 1); + std::span view(value.data(), size); + using Value = std::remove_cvref_t; + detail::to::template op(view, ctx, b, ix); + } + }; } // namespace detail } // namespace glaze diff --git a/tests/eigen_test/eigen_test.cpp b/tests/eigen_test/eigen_test.cpp index 8d8fbcaf9d..6cdbe72da2 100644 --- a/tests/eigen_test/eigen_test.cpp +++ b/tests/eigen_test/eigen_test.cpp @@ -4,6 +4,7 @@ #include "glaze/ext/eigen.hpp" #include +#include #include #include #include @@ -394,4 +395,21 @@ int main() expect(!glz::read_json(e, b)); expect(bool(m == e)); }; + + "Eigen::Transform"_test = [] { + Eigen::Isometry3d pose1, pose2; + pose1.setIdentity(); + pose1.translation() << 1.111, 2.222, 3.333; + std::string buffer = glz::write_json(pose1).value(); + expect(buffer == "[1,0,0,0,0,1,0,0,0,0,1,0,1.111,2.222,3.333,1]"); + expect(not glz::read_json(pose2, buffer)); + expect(pose1.matrix() == pose2.matrix()); + + Eigen::AffineCompact2d c1, c2; + c1.setIdentity(); + buffer = glz::write_json(c1).value(); + expect(buffer == "[1,0,0,1,0,0]"); + expect(not glz::read_json(c2, buffer)); + expect(c1.matrix() == c2.matrix()); + }; }