1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra. Eigen itself is part of the KDE project.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #include "main.h"
12 #include <Eigen/Geometry>
13 #include <Eigen/LU>
14 #include <Eigen/QR>
15 
parametrizedline(const LineType & _line)16 template<typename LineType> void parametrizedline(const LineType& _line)
17 {
18   /* this test covers the following files:
19      ParametrizedLine.h
20   */
21 
22   const int dim = _line.dim();
23   typedef typename LineType::Scalar Scalar;
24   typedef typename NumTraits<Scalar>::Real RealScalar;
25   typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime, 1> VectorType;
26   typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime,
27                          LineType::AmbientDimAtCompileTime> MatrixType;
28 
29   VectorType p0 = VectorType::Random(dim);
30   VectorType p1 = VectorType::Random(dim);
31 
32   VectorType d0 = VectorType::Random(dim).normalized();
33 
34   LineType l0(p0, d0);
35 
36   Scalar s0 = ei_random<Scalar>();
37   Scalar s1 = ei_abs(ei_random<Scalar>());
38 
39   VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0), RealScalar(1) );
40   VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0+s0*d0), RealScalar(1) );
41   VERIFY_IS_APPROX( (l0.projection(p1)-p1).norm(), l0.distance(p1) );
42   VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(l0.projection(p1)), RealScalar(1) );
43   VERIFY_IS_APPROX( Scalar(l0.distance((p0+s0*d0) + d0.unitOrthogonal() * s1)), s1 );
44 
45   // casting
46   const int Dim = LineType::AmbientDimAtCompileTime;
47   typedef typename GetDifferentType<Scalar>::type OtherScalar;
48   ParametrizedLine<OtherScalar,Dim> hp1f = l0.template cast<OtherScalar>();
49   VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),l0);
50   ParametrizedLine<Scalar,Dim> hp1d = l0.template cast<Scalar>();
51   VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),l0);
52 }
53 
test_eigen2_parametrizedline()54 void test_eigen2_parametrizedline()
55 {
56   for(int i = 0; i < g_repeat; i++) {
57     CALL_SUBTEST_1( parametrizedline(ParametrizedLine<float,2>()) );
58     CALL_SUBTEST_2( parametrizedline(ParametrizedLine<float,3>()) );
59     CALL_SUBTEST_3( parametrizedline(ParametrizedLine<double,4>()) );
60     CALL_SUBTEST_4( parametrizedline(ParametrizedLine<std::complex<double>,5>()) );
61   }
62 }
63