mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-07 18:27:40 +08:00
bug #1461: fix compilation of Map<const Quaternion>::x()
This commit is contained in:
parent
fc39d5954b
commit
bc91a2df8b
@ -43,6 +43,11 @@ class QuaternionBase : public RotationBase<Derived, 3>
|
||||
typedef typename internal::traits<Derived>::Scalar Scalar;
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
typedef typename internal::traits<Derived>::Coefficients Coefficients;
|
||||
typedef typename Coefficients::CoeffReturnType CoeffReturnType;
|
||||
typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit),
|
||||
Scalar&, CoeffReturnType>::type NonConstCoeffReturnType;
|
||||
|
||||
|
||||
enum {
|
||||
Flags = Eigen::internal::traits<Derived>::Flags
|
||||
};
|
||||
@ -58,22 +63,22 @@ class QuaternionBase : public RotationBase<Derived, 3>
|
||||
|
||||
|
||||
/** \returns the \c x coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar x() const { return this->derived().coeffs().coeff(0); }
|
||||
EIGEN_DEVICE_FUNC inline CoeffReturnType x() const { return this->derived().coeffs().coeff(0); }
|
||||
/** \returns the \c y coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar y() const { return this->derived().coeffs().coeff(1); }
|
||||
EIGEN_DEVICE_FUNC inline CoeffReturnType y() const { return this->derived().coeffs().coeff(1); }
|
||||
/** \returns the \c z coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar z() const { return this->derived().coeffs().coeff(2); }
|
||||
EIGEN_DEVICE_FUNC inline CoeffReturnType z() const { return this->derived().coeffs().coeff(2); }
|
||||
/** \returns the \c w coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar w() const { return this->derived().coeffs().coeff(3); }
|
||||
EIGEN_DEVICE_FUNC inline CoeffReturnType w() const { return this->derived().coeffs().coeff(3); }
|
||||
|
||||
/** \returns a reference to the \c x coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar& x() { return this->derived().coeffs().coeffRef(0); }
|
||||
/** \returns a reference to the \c y coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar& y() { return this->derived().coeffs().coeffRef(1); }
|
||||
/** \returns a reference to the \c z coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar& z() { return this->derived().coeffs().coeffRef(2); }
|
||||
/** \returns a reference to the \c w coefficient */
|
||||
EIGEN_DEVICE_FUNC inline Scalar& w() { return this->derived().coeffs().coeffRef(3); }
|
||||
/** \returns a reference to the \c x coefficient (if Derived is a non-const lvalue) */
|
||||
EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType x() { return this->derived().coeffs().x(); }
|
||||
/** \returns a reference to the \c y coefficient (if Derived is a non-const lvalue) */
|
||||
EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType y() { return this->derived().coeffs().y(); }
|
||||
/** \returns a reference to the \c z coefficient (if Derived is a non-const lvalue) */
|
||||
EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType z() { return this->derived().coeffs().z(); }
|
||||
/** \returns a reference to the \c w coefficient (if Derived is a non-const lvalue) */
|
||||
EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType w() { return this->derived().coeffs().w(); }
|
||||
|
||||
/** \returns a read-only vector expression of the imaginary part (x,y,z) */
|
||||
EIGEN_DEVICE_FUNC inline const VectorBlock<const Coefficients,3> vec() const { return coeffs().template head<3>(); }
|
||||
|
@ -231,6 +231,19 @@ template<typename Scalar> void mapQuaternion(void){
|
||||
VERIFY_IS_APPROX(mq3*mq2, q3*q2);
|
||||
VERIFY_IS_APPROX(mcq1*mq2, q1*q2);
|
||||
VERIFY_IS_APPROX(mcq3*mq2, q3*q2);
|
||||
|
||||
// Bug 1461, compilation issue with Map<const Quat>::w(), and other reference/constness checks:
|
||||
VERIFY_IS_APPROX(mcq3.coeffs().x() + mcq3.coeffs().y() + mcq3.coeffs().z() + mcq3.coeffs().w(), mcq3.coeffs().sum());
|
||||
VERIFY_IS_APPROX(mcq3.x() + mcq3.y() + mcq3.z() + mcq3.w(), mcq3.coeffs().sum());
|
||||
mq3.w() = 1;
|
||||
const Quaternionx& cq3(q3);
|
||||
VERIFY( &cq3.x() == &q3.x() );
|
||||
const MQuaternionUA& cmq3(mq3);
|
||||
VERIFY( &cmq3.x() == &mq3.x() );
|
||||
// FIXME the following should be ok. The problem is that currently the LValueBit flag
|
||||
// is used to determine wether we can return a coeff by reference or not, which is not enough for Map<const ...>.
|
||||
//const MCQuaternionUA& cmcq3(mcq3);
|
||||
//VERIFY( &cmcq3.x() == &mcq3.x() );
|
||||
}
|
||||
|
||||
template<typename Scalar> void quaternionAlignment(void){
|
||||
|
Loading…
Reference in New Issue
Block a user