eigen2_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. Eigen itself is part of the KDE project.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.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 
00037   const int 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 = ei_random<Scalar>();
00052   Scalar s1 = ei_abs(ei_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 void test_eigen2_parametrizedline()
00070 {
00071   for(int i = 0; i < g_repeat; i++) {
00072     CALL_SUBTEST_1( parametrizedline(ParametrizedLine<float,2>()) );
00073     CALL_SUBTEST_2( parametrizedline(ParametrizedLine<float,3>()) );
00074     CALL_SUBTEST_3( parametrizedline(ParametrizedLine<double,4>()) );
00075     CALL_SUBTEST_4( parametrizedline(ParametrizedLine<std::complex<double>,5>()) );
00076   }
00077 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:38