aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kiazyk <skiazyk@google.com>2016-09-26 11:13:10 -0700
committerAlex Vakulenko <avakulenko@google.com>2017-01-20 11:38:20 -0800
commite49400835d7c1750f86f7c09a37167bf6ffe617a (patch)
treea56b4684d1a5521d5bbdde9a2e0b4efc79721150
parent4bcb9c0a4d400aea49df5f1f87a2e842025283f4 (diff)
downloadeigen-o-preview.tar.gz
eigen: fix Projective * scaling and Projective *= scalingandroid-o-preview-1o-preview
Cherry-pick of commit 9ea0ed9 Bug 1304: fix Projective * scaling and Projective *= scaling Bug: None Test: None (cherry picked from commit 10f19f81392ea3ed4c3f23f26d169b9295d1b7f4) Change-Id: I2a87251e52378681b7e8b68a915c740d604081c0
-rw-r--r--Eigen/src/Geometry/Transform.h6
-rw-r--r--Eigen/src/Geometry/Translation.h6
-rw-r--r--test/geo_transformations.cpp79
3 files changed, 86 insertions, 5 deletions
diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h
index e786e5356..acee2d84c 100644
--- a/Eigen/src/Geometry/Transform.h
+++ b/Eigen/src/Geometry/Transform.h
@@ -424,7 +424,7 @@ public:
operator * (const DiagonalBase<DiagonalDerived> &b) const
{
TransformTimeDiagonalReturnType res(*this);
- res.linear() *= b;
+ res.linearExt() *= b;
return res;
}
@@ -538,7 +538,7 @@ public:
return res;
}
- inline Transform& operator*=(const DiagonalMatrix<Scalar,Dim>& s) { linear() *= s; return *this; }
+ inline Transform& operator*=(const DiagonalMatrix<Scalar,Dim>& s) { linearExt() *= s; return *this; }
template<typename Derived>
inline Transform& operator=(const RotationBase<Derived,Dim>& r);
@@ -809,7 +809,7 @@ Transform<Scalar,Dim,Mode,Options>::prescale(const MatrixBase<OtherDerived> &oth
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim))
EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
- m_matrix.template block<Dim,HDim>(0,0).noalias() = (other.asDiagonal() * m_matrix.template block<Dim,HDim>(0,0));
+ affine().noalias() = (other.asDiagonal() * affine());
return *this;
}
diff --git a/Eigen/src/Geometry/Translation.h b/Eigen/src/Geometry/Translation.h
index 7fda179cc..c8f53eace 100644
--- a/Eigen/src/Geometry/Translation.h
+++ b/Eigen/src/Geometry/Translation.h
@@ -130,8 +130,10 @@ public:
}
/** Applies translation to vector */
- inline VectorType operator* (const VectorType& other) const
- { return m_coeffs + other; }
+ template<typename Derived>
+ inline typename internal::enable_if<Derived::IsVectorAtCompileTime,VectorType>::type
+ operator* (const MatrixBase<Derived>& vec) const
+ { return m_coeffs + vec.derived(); }
/** \returns the inverse translation (opposite) */
Translation inverse() const { return Translation(-m_coeffs); }
diff --git a/test/geo_transformations.cpp b/test/geo_transformations.cpp
index 547765714..4ad3793d8 100644
--- a/test/geo_transformations.cpp
+++ b/test/geo_transformations.cpp
@@ -320,6 +320,9 @@ template<typename Scalar, int Mode, int Options> void transformations()
t0.scale(v0);
t1 *= AlignedScaling3(v0);
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
+ t1 = AlignedScaling3(v0) * (Translation3(v0) * Transform3(q1));
+ t1 = t1 * v0.asDiagonal();
+ VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
// transformation * translation
t0.translate(v0);
t1 = t1 * Translation3(v0);
@@ -437,6 +440,79 @@ template<typename Scalar, int Mode, int Options> void transformations()
Rotation2D<Scalar> r2(r1); // copy ctor
VERIFY_IS_APPROX(r2.angle(),s0);
}
+
+ {
+ Transform3 t32(Matrix4::Random()), t33, t34;
+ t34 = t33 = t32;
+ t32.scale(v0);
+ t33*=AlignedScaling3(v0);
+ VERIFY_IS_APPROX(t32.matrix(), t33.matrix());
+ t33 = t34 * AlignedScaling3(v0);
+ VERIFY_IS_APPROX(t32.matrix(), t33.matrix());
+ }
+
+}
+
+template<typename A1, typename A2, typename P, typename Q, typename V, typename H>
+void transform_associativity_left(const A1& a1, const A2& a2, const P& p, const Q& q, const V& v, const H& h)
+{
+ VERIFY_IS_APPROX( q*(a1*v), (q*a1)*v );
+ VERIFY_IS_APPROX( q*(a2*v), (q*a2)*v );
+ VERIFY_IS_APPROX( q*(p*h).hnormalized(), ((q*p)*h).hnormalized() );
+}
+
+template<typename A1, typename A2, typename P, typename Q, typename V, typename H>
+void transform_associativity2(const A1& a1, const A2& a2, const P& p, const Q& q, const V& v, const H& h)
+{
+ VERIFY_IS_APPROX( a1*(q*v), (a1*q)*v );
+ VERIFY_IS_APPROX( a2*(q*v), (a2*q)*v );
+ VERIFY_IS_APPROX( p *(q*v).homogeneous(), (p *q)*v.homogeneous() );
+
+ transform_associativity_left(a1, a2,p, q, v, h);
+}
+
+template<typename Scalar, int Dim, int Options,typename RotationType>
+void transform_associativity(const RotationType& R)
+{
+ typedef Matrix<Scalar,Dim,1> VectorType;
+ typedef Matrix<Scalar,Dim+1,1> HVectorType;
+ typedef Matrix<Scalar,Dim,Dim> LinearType;
+ typedef Matrix<Scalar,Dim+1,Dim+1> MatrixType;
+ typedef Transform<Scalar,Dim,AffineCompact,Options> AffineCompactType;
+ typedef Transform<Scalar,Dim,Affine,Options> AffineType;
+ typedef Transform<Scalar,Dim,Projective,Options> ProjectiveType;
+ typedef DiagonalMatrix<Scalar,Dim> ScalingType;
+ typedef Translation<Scalar,Dim> TranslationType;
+
+ AffineCompactType A1c; A1c.matrix().setRandom();
+ AffineCompactType A2c; A2c.matrix().setRandom();
+ AffineType A1(A1c);
+ AffineType A2(A2c);
+ ProjectiveType P1; P1.matrix().setRandom();
+ VectorType v1 = VectorType::Random();
+ VectorType v2 = VectorType::Random();
+ HVectorType h1 = HVectorType::Random();
+ Scalar s1 = internal::random<Scalar>();
+ LinearType L = LinearType::Random();
+ MatrixType M = MatrixType::Random();
+
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, A2, v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, A2c, v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, v1.asDiagonal(), v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, ScalingType(v1), v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, Scaling(v1), v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, Scaling(s1), v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, TranslationType(v1), v2, h1) );
+ CALL_SUBTEST( transform_associativity_left(A1c, A1, P1, L, v2, h1) );
+ CALL_SUBTEST( transform_associativity2(A1c, A1, P1, R, v2, h1) );
+
+ VERIFY_IS_APPROX( A1*(M*h1), (A1*M)*h1 );
+ VERIFY_IS_APPROX( A1c*(M*h1), (A1c*M)*h1 );
+ VERIFY_IS_APPROX( P1*(M*h1), (P1*M)*h1 );
+
+ VERIFY_IS_APPROX( M*(A1*h1), (M*A1)*h1 );
+ VERIFY_IS_APPROX( M*(A1c*h1), (M*A1c)*h1 );
+ VERIFY_IS_APPROX( M*(P1*h1), ((M*P1)*h1) );
}
template<typename Scalar> void transform_alignment()
@@ -517,5 +593,8 @@ void test_geo_transformations()
CALL_SUBTEST_7(( transform_products<double,3,RowMajor|AutoAlign>() ));
CALL_SUBTEST_7(( transform_products<float,2,AutoAlign>() ));
+
+ CALL_SUBTEST_8(( transform_associativity<double,2,ColMajor>(Rotation2D<double>(internal::random<double>()*double(EIGEN_PI))) ));
+ CALL_SUBTEST_8(( transform_associativity<double,3,ColMajor>(Quaterniond::UnitRandom()) ));
}
}