eigen2_alignedbox.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 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 #include <Eigen/Geometry>
00027 #include <Eigen/LU>
00028 #include <Eigen/QR>
00029 
00030 template<typename BoxType> void alignedbox(const BoxType& _box)
00031 {
00032   /* this test covers the following files:
00033      AlignedBox.h
00034   */
00035 
00036   const int dim = _box.dim();
00037   typedef typename BoxType::Scalar Scalar;
00038   typedef typename NumTraits<Scalar>::Real RealScalar;
00039   typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
00040 
00041   VectorType p0 = VectorType::Random(dim);
00042   VectorType p1 = VectorType::Random(dim);
00043   RealScalar s1 = ei_random<RealScalar>(0,1);
00044 
00045   BoxType b0(dim);
00046   BoxType b1(VectorType::Random(dim),VectorType::Random(dim));
00047   BoxType b2;
00048 
00049   b0.extend(p0);
00050   b0.extend(p1);
00051   VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1));
00052   VERIFY(!b0.contains(p0 + (1+s1)*(p1-p0)));
00053 
00054   (b2 = b0).extend(b1);
00055   VERIFY(b2.contains(b0));
00056   VERIFY(b2.contains(b1));
00057   VERIFY_IS_APPROX(b2.clamp(b0), b0);
00058 
00059   // casting
00060   const int Dim = BoxType::AmbientDimAtCompileTime;
00061   typedef typename GetDifferentType<Scalar>::type OtherScalar;
00062   AlignedBox<OtherScalar,Dim> hp1f = b0.template cast<OtherScalar>();
00063   VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),b0);
00064   AlignedBox<Scalar,Dim> hp1d = b0.template cast<Scalar>();
00065   VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),b0);
00066 }
00067 
00068 void test_eigen2_alignedbox()
00069 {
00070   for(int i = 0; i < g_repeat; i++) {
00071     CALL_SUBTEST_1( alignedbox(AlignedBox<float,2>()) );
00072     CALL_SUBTEST_2( alignedbox(AlignedBox<float,3>()) );
00073     CALL_SUBTEST_3( alignedbox(AlignedBox<double,4>()) );
00074   }
00075 }


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