Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "main.h"
00027 #include <Eigen/Geometry>
00028 #include <Eigen/LU>
00029 #include <Eigen/QR>
00030
00031 template<typename LineType> void parametrizedline(const LineType& _line)
00032 {
00033
00034
00035
00036 typedef typename LineType::Index Index;
00037 const Index dim = _line.dim();
00038 typedef typename LineType::Scalar Scalar;
00039 typedef typename NumTraits<Scalar>::Real RealScalar;
00040 typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime, 1> VectorType;
00041 typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime,
00042 LineType::AmbientDimAtCompileTime> MatrixType;
00043
00044 VectorType p0 = VectorType::Random(dim);
00045 VectorType p1 = VectorType::Random(dim);
00046
00047 VectorType d0 = VectorType::Random(dim).normalized();
00048
00049 LineType l0(p0, d0);
00050
00051 Scalar s0 = internal::random<Scalar>();
00052 Scalar s1 = internal::abs(internal::random<Scalar>());
00053
00054 VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0), RealScalar(1) );
00055 VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0+s0*d0), RealScalar(1) );
00056 VERIFY_IS_APPROX( (l0.projection(p1)-p1).norm(), l0.distance(p1) );
00057 VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(l0.projection(p1)), RealScalar(1) );
00058 VERIFY_IS_APPROX( Scalar(l0.distance((p0+s0*d0) + d0.unitOrthogonal() * s1)), s1 );
00059
00060
00061 const int Dim = LineType::AmbientDimAtCompileTime;
00062 typedef typename GetDifferentType<Scalar>::type OtherScalar;
00063 ParametrizedLine<OtherScalar,Dim> hp1f = l0.template cast<OtherScalar>();
00064 VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),l0);
00065 ParametrizedLine<Scalar,Dim> hp1d = l0.template cast<Scalar>();
00066 VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),l0);
00067 }
00068
00069 template<typename Scalar> void parametrizedline_alignment()
00070 {
00071 typedef ParametrizedLine<Scalar,4,AutoAlign> Line4a;
00072 typedef ParametrizedLine<Scalar,4,DontAlign> Line4u;
00073
00074 EIGEN_ALIGN16 Scalar array1[8];
00075 EIGEN_ALIGN16 Scalar array2[8];
00076 EIGEN_ALIGN16 Scalar array3[8+1];
00077 Scalar* array3u = array3+1;
00078
00079 Line4a *p1 = ::new(reinterpret_cast<void*>(array1)) Line4a;
00080 Line4u *p2 = ::new(reinterpret_cast<void*>(array2)) Line4u;
00081 Line4u *p3 = ::new(reinterpret_cast<void*>(array3u)) Line4u;
00082
00083 p1->origin().setRandom();
00084 p1->direction().setRandom();
00085 *p2 = *p1;
00086 *p3 = *p1;
00087
00088 VERIFY_IS_APPROX(p1->origin(), p2->origin());
00089 VERIFY_IS_APPROX(p1->origin(), p3->origin());
00090 VERIFY_IS_APPROX(p1->direction(), p2->direction());
00091 VERIFY_IS_APPROX(p1->direction(), p3->direction());
00092
00093 #if defined(EIGEN_VECTORIZE) && EIGEN_ALIGN_STATICALLY
00094 if(internal::packet_traits<Scalar>::Vectorizable)
00095 VERIFY_RAISES_ASSERT((::new(reinterpret_cast<void*>(array3u)) Line4a));
00096 #endif
00097 }
00098
00099 void test_geo_parametrizedline()
00100 {
00101 for(int i = 0; i < g_repeat; i++) {
00102 CALL_SUBTEST_1( parametrizedline(ParametrizedLine<float,2>()) );
00103 CALL_SUBTEST_2( parametrizedline(ParametrizedLine<float,3>()) );
00104 CALL_SUBTEST_2( parametrizedline_alignment<float>() );
00105 CALL_SUBTEST_3( parametrizedline(ParametrizedLine<double,4>()) );
00106 CALL_SUBTEST_3( parametrizedline_alignment<double>() );
00107 CALL_SUBTEST_4( parametrizedline(ParametrizedLine<std::complex<double>,5>()) );
00108 }
00109 }