diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index a9e4e3c6d..f17a639ad 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -61,7 +61,7 @@ template< typename Lhs, typename Rhs, bool AnyProjective = transform_traits::IsProjective || - transform_traits::IsProjective> + transform_traits::IsProjective> struct transform_transform_product_impl; template< typename Other, @@ -1395,6 +1395,35 @@ struct transform_transform_product_impl } }; +template +struct transform_transform_product_impl,Transform,true > +{ + typedef Transform Lhs; + typedef Transform Rhs; + typedef Transform ResultType; + static ResultType run(const Lhs& lhs, const Rhs& rhs) + { + ResultType res; + res.matrix().template topRows() = lhs.matrix() * rhs.matrix(); + res.matrix().row(Dim) = rhs.matrix().row(Dim); + return res; + } +}; + +template +struct transform_transform_product_impl,Transform,true > +{ + typedef Transform Lhs; + typedef Transform Rhs; + typedef Transform ResultType; + static ResultType run(const Lhs& lhs, const Rhs& rhs) + { + ResultType res(lhs.matrix().template leftCols() * rhs.matrix()); + res.matrix().col(Dim) += lhs.matrix().col(Dim); + return res; + } +}; + } // end namespace internal #endif // EIGEN_TRANSFORM_H diff --git a/test/geo_transformations.cpp b/test/geo_transformations.cpp index 9156954a2..e9f05cfb6 100644 --- a/test/geo_transformations.cpp +++ b/test/geo_transformations.cpp @@ -446,6 +446,29 @@ template void transform_alignment() #endif } +template void transform_products() +{ + typedef Matrix Mat; + typedef Transform Proj; + typedef Transform Aff; + typedef Transform AffC; + + Proj p; p.matrix().setRandom(); + Aff a; a.linear().setRandom(); a.translation().setRandom(); + AffC ac = a; + + Mat p_m(p.matrix()), a_m(a.matrix()); + + VERIFY_IS_APPROX((p*p).matrix(), p_m*p_m); + VERIFY_IS_APPROX((a*a).matrix(), a_m*a_m); + VERIFY_IS_APPROX((p*a).matrix(), p_m*a_m); + VERIFY_IS_APPROX((a*p).matrix(), a_m*p_m); + VERIFY_IS_APPROX((ac*a).matrix(), a_m*a_m); + VERIFY_IS_APPROX((a*ac).matrix(), a_m*a_m); + VERIFY_IS_APPROX((p*ac).matrix(), p_m*a_m); + VERIFY_IS_APPROX((ac*p).matrix(), a_m*p_m); +} + void test_geo_transformations() { for(int i = 0; i < g_repeat; i++) { @@ -468,5 +491,9 @@ void test_geo_transformations() CALL_SUBTEST_6(( transformations() )); CALL_SUBTEST_6(( transformations() )); + + + CALL_SUBTEST_7(( transform_products() )); + CALL_SUBTEST_7(( transform_products() )); } }