diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 3c5f91533..e873f15cb 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -247,8 +247,8 @@ template class Scaling; #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS template class Transform; -template class ParametrizedLine; -template class Hyperplane; +template class ParametrizedLine; +template class Hyperplane; template class UniformScaling; template class Homogeneous; #endif diff --git a/Eigen/src/Geometry/Hyperplane.h b/Eigen/src/Geometry/Hyperplane.h index f22b23a24..e43c9d07d 100644 --- a/Eigen/src/Geometry/Hyperplane.h +++ b/Eigen/src/Geometry/Hyperplane.h @@ -43,24 +43,32 @@ * \f$ n \cdot x + d = 0 \f$ where \f$ n \f$ is a unit normal vector of the plane (linear part) * and \f$ d \f$ is the distance (offset) to the origin. */ -template +template class Hyperplane { public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==Dynamic ? Dynamic : _AmbientDim+1) - enum { AmbientDimAtCompileTime = _AmbientDim }; + enum { + AmbientDimAtCompileTime = _AmbientDim, + Options = _Options + }; typedef _Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef DenseIndex Index; typedef Matrix VectorType; typedef Matrix Coefficients; + : Index(AmbientDimAtCompileTime)+1,1,Options> Coefficients; typedef Block NormalReturnType; typedef const Block ConstNormalReturnType; /** Default constructor without initialization */ inline explicit Hyperplane() {} + + template + Hyperplane(const Hyperplane& other) + : m_coeffs(other.coeffs()) + {} /** Constructs a dynamic-size hyperplane with \a _dim the dimension * of the ambient space */ @@ -245,22 +253,23 @@ public: */ template inline typename internal::cast_return_type >::type cast() const + Hyperplane >::type cast() const { return typename internal::cast_return_type >::type(*this); + Hyperplane >::type(*this); } /** Copy constructor with scalar type conversion */ - template - inline explicit Hyperplane(const Hyperplane& other) + template + inline explicit Hyperplane(const Hyperplane& other) { m_coeffs = other.coeffs().template cast(); } /** \returns \c true if \c *this is approximately equal to \a other, within the precision * determined by \a prec. * * \sa MatrixBase::isApprox() */ - bool isApprox(const Hyperplane& other, typename NumTraits::Real prec = NumTraits::dummy_precision()) const + template + bool isApprox(const Hyperplane& other, typename NumTraits::Real prec = NumTraits::dummy_precision()) const { return m_coeffs.isApprox(other.m_coeffs, prec); } protected: diff --git a/Eigen/src/Geometry/ParametrizedLine.h b/Eigen/src/Geometry/ParametrizedLine.h index 858cdf6a8..edad5f8ee 100644 --- a/Eigen/src/Geometry/ParametrizedLine.h +++ b/Eigen/src/Geometry/ParametrizedLine.h @@ -39,19 +39,27 @@ * \param _Scalar the scalar type, i.e., the type of the coefficients * \param _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic. */ -template +template class ParametrizedLine { public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) - enum { AmbientDimAtCompileTime = _AmbientDim }; + enum { + AmbientDimAtCompileTime = _AmbientDim, + Options = _Options + }; typedef _Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef DenseIndex Index; - typedef Matrix VectorType; + typedef Matrix VectorType; /** Default constructor without initialization */ inline explicit ParametrizedLine() {} + + template + ParametrizedLine(const ParametrizedLine& other) + : m_origin(other.origin()), m_direction(other.direction()) + {} /** Constructs a dynamic-size line with \a _dim the dimension * of the ambient space */ @@ -63,7 +71,8 @@ public: ParametrizedLine(const VectorType& origin, const VectorType& direction) : m_origin(origin), m_direction(direction) {} - explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane); + template + explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane); /** Constructs a parametrized line going from \a p0 to \a p1. */ static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1) @@ -97,7 +106,8 @@ public: VectorType projection(const VectorType& p) const { return origin() + direction().dot(p-origin()) * direction(); } - Scalar intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane); + template + Scalar intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane); /** \returns \c *this with scalar type casted to \a NewScalarType * @@ -106,15 +116,15 @@ public: */ template inline typename internal::cast_return_type >::type cast() const + ParametrizedLine >::type cast() const { return typename internal::cast_return_type >::type(*this); + ParametrizedLine >::type(*this); } /** Copy constructor with scalar type conversion */ - template - inline explicit ParametrizedLine(const ParametrizedLine& other) + template + inline explicit ParametrizedLine(const ParametrizedLine& other) { m_origin = other.origin().template cast(); m_direction = other.direction().template cast(); @@ -136,8 +146,9 @@ protected: * * \warning the ambient space must have dimension 2 such that the hyperplane actually describes a line */ -template -inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane) +template +template +inline ParametrizedLine<_Scalar, _AmbientDim,_Options>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim,OtherOptions>& hyperplane) { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2) direction() = hyperplane.normal().unitOrthogonal(); @@ -146,8 +157,9 @@ inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane /** \returns the parameter value of the intersection between \c *this and the given hyperplane */ -template -inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane) +template +template +inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) { return -(hyperplane.offset()+hyperplane.normal().dot(origin())) / hyperplane.normal().dot(direction()); diff --git a/test/geo_hyperplane.cpp b/test/geo_hyperplane.cpp index 23027f38e..de3c6df0b 100644 --- a/test/geo_hyperplane.cpp +++ b/test/geo_hyperplane.cpp @@ -35,6 +35,7 @@ template void hyperplane(const HyperplaneType& _plane) */ typedef typename HyperplaneType::Index Index; const Index dim = _plane.dim(); + enum { Options = HyperplaneType::Options }; typedef typename HyperplaneType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef Matrix VectorType; @@ -85,9 +86,9 @@ template void hyperplane(const HyperplaneType& _plane) // casting const int Dim = HyperplaneType::AmbientDimAtCompileTime; typedef typename GetDifferentType::type OtherScalar; - Hyperplane hp1f = pl1.template cast(); + Hyperplane hp1f = pl1.template cast(); VERIFY_IS_APPROX(hp1f.template cast(),pl1); - Hyperplane hp1d = pl1.template cast(); + Hyperplane hp1d = pl1.template cast(); VERIFY_IS_APPROX(hp1d.template cast(),pl1); } @@ -128,11 +129,40 @@ template void lines() } } +template void hyperplane_alignment() +{ + typedef Hyperplane Plane3a; + typedef Hyperplane Plane3u; + + EIGEN_ALIGN16 Scalar array1[4]; + EIGEN_ALIGN16 Scalar array2[4]; + EIGEN_ALIGN16 Scalar array3[4+1]; + Scalar* array3u = array3+1; + + Plane3a *p1 = ::new(reinterpret_cast(array1)) Plane3a; + Plane3u *p2 = ::new(reinterpret_cast(array2)) Plane3u; + Plane3u *p3 = ::new(reinterpret_cast(array3u)) Plane3u; + + p1->coeffs().setRandom(); + *p2 = *p1; + *p3 = *p1; + + VERIFY_IS_APPROX(p1->coeffs(), p2->coeffs()); + VERIFY_IS_APPROX(p1->coeffs(), p3->coeffs()); + + #ifdef EIGEN_VECTORIZE + VERIFY_RAISES_ASSERT((::new(reinterpret_cast(array3u)) Plane3a)); + #endif +} + + void test_geo_hyperplane() { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( hyperplane(Hyperplane()) ); CALL_SUBTEST_2( hyperplane(Hyperplane()) ); + CALL_SUBTEST_2( hyperplane(Hyperplane()) ); + CALL_SUBTEST_2( hyperplane_alignment() ); CALL_SUBTEST_3( hyperplane(Hyperplane()) ); CALL_SUBTEST_4( hyperplane(Hyperplane,5>()) ); CALL_SUBTEST_1( lines() ); diff --git a/test/geo_parametrizedline.cpp b/test/geo_parametrizedline.cpp index 36b38b979..460455eec 100644 --- a/test/geo_parametrizedline.cpp +++ b/test/geo_parametrizedline.cpp @@ -66,12 +66,42 @@ template void parametrizedline(const LineType& _line) VERIFY_IS_APPROX(hp1d.template cast(),l0); } +template void parametrizedline_alignment() +{ + typedef ParametrizedLine Line4a; + typedef ParametrizedLine Line4u; + + EIGEN_ALIGN16 Scalar array1[8]; + EIGEN_ALIGN16 Scalar array2[8]; + EIGEN_ALIGN16 Scalar array3[8+1]; + Scalar* array3u = array3+1; + + Line4a *p1 = ::new(reinterpret_cast(array1)) Line4a; + Line4u *p2 = ::new(reinterpret_cast(array2)) Line4u; + Line4u *p3 = ::new(reinterpret_cast(array3u)) Line4u; + + p1->origin().setRandom(); + p1->direction().setRandom(); + *p2 = *p1; + *p3 = *p1; + + VERIFY_IS_APPROX(p1->origin(), p2->origin()); + VERIFY_IS_APPROX(p1->origin(), p3->origin()); + VERIFY_IS_APPROX(p1->direction(), p2->direction()); + VERIFY_IS_APPROX(p1->direction(), p3->direction()); + + #ifdef EIGEN_VECTORIZE + VERIFY_RAISES_ASSERT((::new(reinterpret_cast(array3u)) Line4a)); + #endif +} + void test_geo_parametrizedline() { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( parametrizedline(ParametrizedLine()) ); CALL_SUBTEST_2( parametrizedline(ParametrizedLine()) ); CALL_SUBTEST_3( parametrizedline(ParametrizedLine()) ); + CALL_SUBTEST_3( parametrizedline_alignment() ); CALL_SUBTEST_4( parametrizedline(ParametrizedLine,5>()) ); } } diff --git a/test/geo_transformations.cpp b/test/geo_transformations.cpp index 317ed9a31..13305ddc8 100644 --- a/test/geo_transformations.cpp +++ b/test/geo_transformations.cpp @@ -429,17 +429,17 @@ template void transformations() template void transform_alignment() { - typedef Transform Projective4a; - typedef Transform Projective4u; + typedef Transform Projective3a; + typedef Transform Projective3u; EIGEN_ALIGN16 Scalar array1[16]; EIGEN_ALIGN16 Scalar array2[16]; EIGEN_ALIGN16 Scalar array3[16+1]; Scalar* array3u = array3+1; - Projective4a *p1 = ::new(reinterpret_cast(array1)) Projective4a; - Projective4u *p2 = ::new(reinterpret_cast(array2)) Projective4u; - Projective4u *p3 = ::new(reinterpret_cast(array3u)) Projective4u; + Projective3a *p1 = ::new(reinterpret_cast(array1)) Projective3a; + Projective3u *p2 = ::new(reinterpret_cast(array2)) Projective3u; + Projective3u *p3 = ::new(reinterpret_cast(array3u)) Projective3u; p1->matrix().setRandom(); *p2 = *p1;