diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-12-22 17:45:37 -0500 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-12-22 17:45:37 -0500 |
commit | 75b7d98665dd144c44d7a113c6613f5f998be626 (patch) | |
tree | bc75d316e2ed8e679e744bc34f159dcb0f285243 /Eigen/src/Geometry | |
parent | 3b6d97b51a7e7a4b0c69ae6be44b1c16d72c2e80 (diff) |
bug #54 - really fix const correctness except in Sparse
Diffstat (limited to 'Eigen/src/Geometry')
-rw-r--r-- | Eigen/src/Geometry/Homogeneous.h | 68 | ||||
-rw-r--r-- | Eigen/src/Geometry/Hyperplane.h | 3 | ||||
-rw-r--r-- | Eigen/src/Geometry/Quaternion.h | 2 | ||||
-rw-r--r-- | Eigen/src/Geometry/Transform.h | 23 |
4 files changed, 59 insertions, 37 deletions
diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index 5a1e0aa4a..24ec66249 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -113,23 +113,11 @@ template<typename MatrixType,int _Direction> class Homogeneous } template<typename Scalar, int Dim, int Mode> friend - inline const internal::homogeneous_left_product_impl<Homogeneous, - typename Transform<Scalar,Dim,Mode>::AffinePartNested> - operator* (const Transform<Scalar,Dim,Mode>& tr, const Homogeneous& rhs) + inline const internal::homogeneous_left_product_impl<Homogeneous,Transform<Scalar,Dim,Mode> > + operator* (const Transform<Scalar,Dim,Mode>& lhs, const Homogeneous& rhs) { eigen_assert(int(Direction)==Vertical); - return internal::homogeneous_left_product_impl<Homogeneous,typename Transform<Scalar,Dim,Mode>::AffinePartNested > - (tr.affine(),rhs.m_matrix); - } - - template<typename Scalar, int Dim> friend - inline const internal::homogeneous_left_product_impl<Homogeneous, - typename Transform<Scalar,Dim,Projective>::MatrixType> - operator* (const Transform<Scalar,Dim,Projective>& tr, const Homogeneous& rhs) - { - eigen_assert(int(Direction)==Vertical); - return internal::homogeneous_left_product_impl<Homogeneous,typename Transform<Scalar,Dim,Projective>::MatrixType> - (tr.matrix(),rhs.m_matrix); + return internal::homogeneous_left_product_impl<Homogeneous,Transform<Scalar,Dim,Mode> >(lhs,rhs.m_matrix); } protected: @@ -179,11 +167,11 @@ VectorwiseOp<ExpressionType,Direction>::homogeneous() const * * \sa VectorwiseOp::hnormalized() */ template<typename Derived> -inline typename MatrixBase<Derived>::HNormalizedReturnType +inline const typename MatrixBase<Derived>::HNormalizedReturnType MatrixBase<Derived>::hnormalized() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return StartMinusOne(derived(),0,0, + return ConstStartMinusOne(derived(),0,0, ColsAtCompileTime==1?size()-1:1, ColsAtCompileTime==1?1:size()-1) / coeff(size()-1); } @@ -197,7 +185,7 @@ MatrixBase<Derived>::hnormalized() const * * \sa MatrixBase::hnormalized() */ template<typename ExpressionType, int Direction> -inline typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType +inline const typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType VectorwiseOp<ExpressionType,Direction>::hnormalized() const { return HNormalized_Block(_expression(),0,0, @@ -217,15 +205,39 @@ VectorwiseOp<ExpressionType,Direction>::hnormalized() const namespace internal { +template<typename MatrixOrTransformType> +struct take_matrix_for_product +{ + typedef MatrixOrTransformType type; + static const type& run(const type &x) { return x; } +}; + +template<typename Scalar, int Dim, int Mode> +struct take_matrix_for_product<Transform<Scalar, Dim, Mode> > +{ + typedef Transform<Scalar, Dim, Mode> TransformType; + typedef typename TransformType::ConstAffinePart type; + static const type run (const TransformType& x) { return x.affine(); } +}; + +template<typename Scalar, int Dim> +struct take_matrix_for_product<Transform<Scalar, Dim, Projective> > +{ + typedef Transform<Scalar, Dim, Projective> TransformType; + typedef typename TransformType::MatrixType type; + static const type& run (const TransformType& x) { return x.matrix(); } +}; + template<typename MatrixType,typename Lhs> struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> > { + typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType; typedef typename make_proper_matrix_type< typename traits<MatrixType>::Scalar, - Lhs::RowsAtCompileTime, + LhsMatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime, MatrixType::PlainObject::Options, - Lhs::MaxRowsAtCompileTime, + LhsMatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime>::type ReturnType; }; @@ -233,10 +245,12 @@ template<typename MatrixType,typename Lhs> struct homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> : public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> > { - typedef typename remove_all<typename Lhs::Nested>::type LhsNested; + typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType; + typedef typename remove_all<typename LhsMatrixType::Nested>::type LhsMatrixTypeNested; typedef typename MatrixType::Index Index; homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs) - : m_lhs(lhs), m_rhs(rhs) + : m_lhs(take_matrix_for_product<Lhs>::run(lhs)), + m_rhs(rhs) {} inline Index rows() const { return m_lhs.rows(); } @@ -245,15 +259,15 @@ struct homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> template<typename Dest> void evalTo(Dest& dst) const { // FIXME investigate how to allow lazy evaluation of this product when possible - dst = Block<LhsNested, - LhsNested::RowsAtCompileTime, - LhsNested::ColsAtCompileTime==Dynamic?Dynamic:LhsNested::ColsAtCompileTime-1> + dst = Block<const LhsMatrixTypeNested, + LhsMatrixTypeNested::RowsAtCompileTime, + LhsMatrixTypeNested::ColsAtCompileTime==Dynamic?Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1> (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs; dst += m_lhs.col(m_lhs.cols()-1).rowwise() .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols()); } - const typename Lhs::Nested m_lhs; + const typename LhsMatrixType::Nested m_lhs; const typename MatrixType::Nested m_rhs; }; @@ -284,7 +298,7 @@ struct homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> template<typename Dest> void evalTo(Dest& dst) const { // FIXME investigate how to allow lazy evaluation of this product when possible - dst = m_lhs * Block<RhsNested, + dst = m_lhs * Block<const RhsNested, RhsNested::RowsAtCompileTime==Dynamic?Dynamic:RhsNested::RowsAtCompileTime-1, RhsNested::ColsAtCompileTime> (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols()); diff --git a/Eigen/src/Geometry/Hyperplane.h b/Eigen/src/Geometry/Hyperplane.h index 852aef185..b532cad04 100644 --- a/Eigen/src/Geometry/Hyperplane.h +++ b/Eigen/src/Geometry/Hyperplane.h @@ -57,6 +57,7 @@ public: ? Dynamic : Index(AmbientDimAtCompileTime)+1,1> Coefficients; typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType; + typedef const Block<const Coefficients,AmbientDimAtCompileTime,1> ConstNormalReturnType; /** Default constructor without initialization */ inline explicit Hyperplane() {} @@ -148,7 +149,7 @@ public: /** \returns a constant reference to the unit normal vector of the plane, which corresponds * to the linear part of the implicit equation. */ - inline const NormalReturnType normal() const { return NormalReturnType(m_coeffs,0,0,dim(),1); } + inline ConstNormalReturnType normal() const { return ConstNormalReturnType(m_coeffs,0,0,dim(),1); } /** \returns a non-constant reference to the unit normal vector of the plane, which corresponds * to the linear part of the implicit equation. diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index 2c4098fc1..d9b34a385 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -79,7 +79,7 @@ public: inline Scalar& w() { return this->derived().coeffs().coeffRef(3); } /** \returns a read-only vector expression of the imaginary part (x,y,z) */ - inline const VectorBlock<Coefficients,3> vec() const { return coeffs().template head<3>(); } + inline const VectorBlock<const Coefficients,3> vec() const { return coeffs().template head<3>(); } /** \returns a vector expression of the imaginary part (x,y,z) */ inline VectorBlock<Coefficients,3> vec() { return coeffs().template head<3>(); } diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index f7c3bd376..0d169abb6 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -193,22 +193,28 @@ public: typedef DenseIndex Index; /** type of the matrix used to represent the transformation */ typedef Matrix<Scalar,Rows,HDim> MatrixType; + /** constified MatrixType */ + typedef const MatrixType ConstMatrixType; /** type of the matrix used to represent the linear part of the transformation */ typedef Matrix<Scalar,Dim,Dim> LinearMatrixType; /** type of read/write reference to the linear part of the transformation */ typedef Block<MatrixType,Dim,Dim> LinearPart; + /** type of read reference to the linear part of the transformation */ + typedef const Block<ConstMatrixType,Dim,Dim> ConstLinearPart; /** type of read/write reference to the affine part of the transformation */ typedef typename internal::conditional<int(Mode)==int(AffineCompact), MatrixType&, Block<MatrixType,Dim,HDim> >::type AffinePart; - /** type of read/write reference to the affine part of the transformation */ + /** type of read reference to the affine part of the transformation */ typedef typename internal::conditional<int(Mode)==int(AffineCompact), - MatrixType&, - Block<MatrixType,Dim,HDim> >::type AffinePartNested; + const MatrixType&, + const Block<const MatrixType,Dim,HDim> >::type ConstAffinePart; /** type of a vector */ typedef Matrix<Scalar,Dim,1> VectorType; /** type of a read/write reference to the translation part of the rotation */ typedef Block<MatrixType,Dim,1> TranslationPart; + /** type of a read reference to the translation part of the rotation */ + typedef const Block<ConstMatrixType,Dim,1> ConstTranslationPart; /** corresponding translation type */ typedef Translation<Scalar,Dim> TranslationType; @@ -336,17 +342,17 @@ public: inline MatrixType& matrix() { return m_matrix; } /** \returns a read-only expression of the linear part of the transformation */ - inline const LinearPart linear() const { return m_matrix.template block<Dim,Dim>(0,0); } + inline ConstLinearPart linear() const { return m_matrix.template block<Dim,Dim>(0,0); } /** \returns a writable expression of the linear part of the transformation */ inline LinearPart linear() { return m_matrix.template block<Dim,Dim>(0,0); } /** \returns a read-only expression of the Dim x HDim affine part of the transformation */ - inline const AffinePart affine() const { return take_affine_part::run(m_matrix); } + inline ConstAffinePart affine() const { return take_affine_part::run(m_matrix); } /** \returns a writable expression of the Dim x HDim affine part of the transformation */ inline AffinePart affine() { return take_affine_part::run(m_matrix); } /** \returns a read-only expression of the translation vector of the transformation */ - inline const TranslationPart translation() const { return m_matrix.template block<Dim,1>(0,Dim); } + inline ConstTranslationPart translation() const { return m_matrix.template block<Dim,1>(0,Dim); } /** \returns a writable expression of the translation vector of the transformation */ inline TranslationPart translation() { return m_matrix.template block<Dim,1>(0,Dim); } @@ -1083,9 +1089,10 @@ namespace internal { template<typename TransformType> struct transform_take_affine_part { typedef typename TransformType::MatrixType MatrixType; typedef typename TransformType::AffinePart AffinePart; + typedef typename TransformType::ConstAffinePart ConstAffinePart; static inline AffinePart run(MatrixType& m) { return m.template block<TransformType::Dim,TransformType::HDim>(0,0); } - static inline const AffinePart run(const MatrixType& m) + static inline ConstAffinePart run(const MatrixType& m) { return m.template block<TransformType::Dim,TransformType::HDim>(0,0); } }; @@ -1180,7 +1187,7 @@ struct transform_right_product_impl< TransformType, MatrixType, false > EIGEN_STATIC_ASSERT(OtherRows==Dim || OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); typedef Block<ResultType, Dim, OtherCols> TopLeftLhs; - typedef Block<MatrixType, Dim, OtherCols> TopLeftRhs; + typedef Block<const MatrixType, Dim, OtherCols> TopLeftRhs; ResultType res(other.rows(),other.cols()); |