diff options
author | Benoit Jacob <bjacob@mozilla.com> | 2010-08-16 12:30:33 -0400 |
---|---|---|
committer | Benoit Jacob <bjacob@mozilla.com> | 2010-08-16 12:30:33 -0400 |
commit | 87aafc9169cd549213c8a950bbeabada109b00ef (patch) | |
tree | affd6bdf80492df485bf97d6d28111414dac1b98 | |
parent | 19d9c835e0c541cd106ade734b9d6b5f36622c28 (diff) |
fix Transform() constructor taking a Transform with other mode.
Not really tested as the geometry tests are currently busted.
-rw-r--r-- | Eigen/src/Core/util/StaticAssert.h | 4 | ||||
-rw-r--r-- | Eigen/src/Geometry/Transform.h | 27 |
2 files changed, 27 insertions, 4 deletions
diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h index d285f79b1..23fb84c6c 100644 --- a/Eigen/src/Core/util/StaticAssert.h +++ b/Eigen/src/Core/util/StaticAssert.h @@ -62,6 +62,7 @@ THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE, THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE, YOU_MADE_A_PROGRAMMING_MISTAKE, + EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT, EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE, YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR, YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR, @@ -88,7 +89,8 @@ THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD, PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS, - YOU_CANNOT_MIX_ARRAYS_AND_MATRICES + YOU_CANNOT_MIX_ARRAYS_AND_MATRICES, + YOU_CANT_CONVERT_A_PROJECTIVE_TRANSFORM_INTO_AN_AFFINE_TRANSFORM }; }; diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index 5a0bb5e29..214b286bd 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -243,9 +243,30 @@ public: template<int OtherMode> inline Transform(const Transform<Scalar,Dim,OtherMode>& other) { - ei_assert(OtherMode!=int(Projective) && "You cannot directly assign a projective transform to an affine one."); - typedef typename Transform<Scalar,Dim,OtherMode>::MatrixType OtherMatrixType; - ei_transform_construct_from_matrix<OtherMatrixType,Mode,Dim,HDim>::run(this, other.matrix()); + EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(OtherMode==int(Projective), Mode==int(Projective)), + YOU_CANT_CONVERT_A_PROJECTIVE_TRANSFORM_INTO_AN_AFFINE_TRANSFORM) + + enum { ModeIsAffineCompact = Mode == int(AffineCompact), + OtherModeIsAffineCompact = OtherMode == int(AffineCompact) + }; + + if(ModeIsAffineCompact == OtherModeIsAffineCompact) + { + m_matrix = other.matrix(); + } + else if(OtherModeIsAffineCompact) + { + typedef typename Transform<Scalar,Dim,OtherMode>::MatrixType OtherMatrixType; + ei_transform_construct_from_matrix<OtherMatrixType,Mode,Dim,HDim>::run(this, other.matrix()); + } + else + { + // here we know that Mode == AffineCompact and OtherMode != AffineCompact. + // if OtherMode were Projective, the static assert above would already have caught it. + // So the only possibility is that OtherMode == Affine + linear() = other.linear(); + translation() = other.translation(); + } } template<typename OtherDerived> |