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 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 #include <Eigen/Geometry>
12 #include <Eigen/LU>
13 #include <Eigen/QR>
14 
alignedbox(const BoxType & _box)15 template<typename BoxType> void alignedbox(const BoxType& _box)
16 {
17   /* this test covers the following files:
18      AlignedBox.h
19   */
20 
21   const int dim = _box.dim();
22   typedef typename BoxType::Scalar Scalar;
23   typedef typename NumTraits<Scalar>::Real RealScalar;
24   typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
25 
26   VectorType p0 = VectorType::Random(dim);
27   VectorType p1 = VectorType::Random(dim);
28   RealScalar s1 = ei_random<RealScalar>(0,1);
29 
30   BoxType b0(dim);
31   BoxType b1(VectorType::Random(dim),VectorType::Random(dim));
32   BoxType b2;
33 
34   b0.extend(p0);
35   b0.extend(p1);
36   VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1));
37   VERIFY(!b0.contains(p0 + (1+s1)*(p1-p0)));
38 
39   (b2 = b0).extend(b1);
40   VERIFY(b2.contains(b0));
41   VERIFY(b2.contains(b1));
42   VERIFY_IS_APPROX(b2.clamp(b0), b0);
43 
44   // casting
45   const int Dim = BoxType::AmbientDimAtCompileTime;
46   typedef typename GetDifferentType<Scalar>::type OtherScalar;
47   AlignedBox<OtherScalar,Dim> hp1f = b0.template cast<OtherScalar>();
48   VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),b0);
49   AlignedBox<Scalar,Dim> hp1d = b0.template cast<Scalar>();
50   VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),b0);
51 }
52 
test_eigen2_alignedbox()53 void test_eigen2_alignedbox()
54 {
55   for(int i = 0; i < g_repeat; i++) {
56     CALL_SUBTEST_1( alignedbox(AlignedBox<float,2>()) );
57     CALL_SUBTEST_2( alignedbox(AlignedBox<float,3>()) );
58     CALL_SUBTEST_3( alignedbox(AlignedBox<double,4>()) );
59   }
60 }
61