geo_parametrizedline.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
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   /* this test covers the following files:
00034      ParametrizedLine.h
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   // casting
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 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:16