From e92993d7b9bf7120563239c4e7d2a53c7d892cd4 Mon Sep 17 00:00:00 2001 From: Hauke Heibel Date: Thu, 29 Jul 2010 16:17:42 +0200 Subject: [PATCH] Safeguarded some Transform functions with compile time asserts. Added missing static Identity() to Rotation2D, AngleAxis. --- Eigen/src/Core/util/StaticAssert.h | 3 ++- Eigen/src/Geometry/AngleAxis.h | 2 ++ Eigen/src/Geometry/Rotation2D.h | 2 ++ Eigen/src/Geometry/Transform.h | 16 +++++++++++----- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h index bf686975b..f1d9d7b3d 100644 --- a/Eigen/src/Core/util/StaticAssert.h +++ b/Eigen/src/Core/util/StaticAssert.h @@ -86,7 +86,8 @@ YOU_ALREADY_SPECIFIED_THIS_STRIDE, INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION, THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD, - PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1 + PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1, + THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS }; }; diff --git a/Eigen/src/Geometry/AngleAxis.h b/Eigen/src/Geometry/AngleAxis.h index af47cc27d..8319aa6f1 100644 --- a/Eigen/src/Geometry/AngleAxis.h +++ b/Eigen/src/Geometry/AngleAxis.h @@ -142,6 +142,8 @@ public: m_angle = Scalar(other.angle()); } + inline static const AngleAxis Identity() { return AngleAxis(0, Vector3::UnitX()); } + /** \returns \c true if \c *this is approximately equal to \a other, within the precision * determined by \a prec. * diff --git a/Eigen/src/Geometry/Rotation2D.h b/Eigen/src/Geometry/Rotation2D.h index 7872c003b..c65b4b6e0 100644 --- a/Eigen/src/Geometry/Rotation2D.h +++ b/Eigen/src/Geometry/Rotation2D.h @@ -117,6 +117,8 @@ public: m_angle = Scalar(other.angle()); } + inline static Rotation2D Identity() { return Rotation2D(0); } + /** \returns \c true if \c *this is approximately equal to \a other, within the precision * determined by \a prec. * diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index 68fda1323..083491f7d 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -202,7 +202,7 @@ protected: public: - /** Default constructor without initialization of the meaningfull coefficients. + /** Default constructor without initialization of the meaningful coefficients. * If Mode==Affine, then the last row is set to [0 ... 0 1] */ inline Transform() { @@ -271,10 +271,10 @@ public: #endif /** shortcut for m_matrix(row,col); - * \sa MatrixBase::operaror(Index,Index) const */ + * \sa MatrixBase::operator(Index,Index) const */ inline Scalar operator() (Index row, Index col) const { return m_matrix(row,col); } /** shortcut for m_matrix(row,col); - * \sa MatrixBase::operaror(Index,Index) */ + * \sa MatrixBase::operator(Index,Index) */ inline Scalar& operator() (Index row, Index col) { return m_matrix(row,col); } /** \returns a read-only expression of the transformation matrix */ @@ -329,13 +329,13 @@ public: template inline Transform& operator*=(const EigenBase& other) { return *this = *this * other; } - /** Contatenates two transformations */ + /** Concatenates two transformations */ inline const Transform operator * (const Transform& other) const { return ei_transform_transform_product_impl::run(*this,other); } - /** Contatenates two different transformations */ + /** Concatenates two different transformations */ template inline const typename ei_transform_transform_product_impl< Transform,Transform >::ResultType @@ -618,6 +618,7 @@ Transform& Transform::scale(const MatrixBase &other) { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim)) + EIGEN_STATIC_ASSERT(Mode!=Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) linearExt().noalias() = (linearExt() * other.asDiagonal()); return *this; } @@ -629,6 +630,7 @@ Transform::scale(const MatrixBase &other) template inline Transform& Transform::scale(Scalar s) { + EIGEN_STATIC_ASSERT(Mode!=Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) linearExt() *= s; return *this; } @@ -643,6 +645,7 @@ Transform& Transform::prescale(const MatrixBase &other) { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim)) + EIGEN_STATIC_ASSERT(Mode!=Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) m_matrix.template block(0,0).noalias() = (other.asDiagonal() * m_matrix.template block(0,0)); return *this; } @@ -654,6 +657,7 @@ Transform::prescale(const MatrixBase &other) template inline Transform& Transform::prescale(Scalar s) { + EIGEN_STATIC_ASSERT(Mode!=Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) m_matrix.template topRows() *= s; return *this; } @@ -742,6 +746,7 @@ Transform& Transform::shear(Scalar sx, Scalar sy) { EIGEN_STATIC_ASSERT(int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE) + EIGEN_STATIC_ASSERT(Mode!=Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) VectorType tmp = linear().col(0)*sy + linear().col(1); linear() << linear().col(0) + linear().col(1)*sx, tmp; return *this; @@ -757,6 +762,7 @@ Transform& Transform::preshear(Scalar sx, Scalar sy) { EIGEN_STATIC_ASSERT(int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE) + EIGEN_STATIC_ASSERT(Mode!=Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) m_matrix.template block(0,0) = LinearMatrixType(1, sx, sy, 1) * m_matrix.template block(0,0); return *this; }