You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

  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. #include "main.h"
  10. #include <Eigen/Geometry>
  11. #include <Eigen/LU>
  12. #include <Eigen/QR>
  13. template<typename BoxType> void alignedbox(const BoxType& _box)
  14. {
  15. /* this test covers the following files:
  16. AlignedBox.h
  17. */
  18. const int dim = _box.dim();
  19. typedef typename BoxType::Scalar Scalar;
  20. typedef typename NumTraits<Scalar>::Real RealScalar;
  21. typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
  22. VectorType p0 = VectorType::Random(dim);
  23. VectorType p1 = VectorType::Random(dim);
  24. RealScalar s1 = ei_random<RealScalar>(0,1);
  25. BoxType b0(dim);
  26. BoxType b1(VectorType::Random(dim),VectorType::Random(dim));
  27. BoxType b2;
  28. b0.extend(p0);
  29. b0.extend(p1);
  30. VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1));
  31. VERIFY(!b0.contains(p0 + (1+s1)*(p1-p0)));
  32. (b2 = b0).extend(b1);
  33. VERIFY(b2.contains(b0));
  34. VERIFY(b2.contains(b1));
  35. VERIFY_IS_APPROX(b2.clamp(b0), b0);
  36. // casting
  37. const int Dim = BoxType::AmbientDimAtCompileTime;
  38. typedef typename GetDifferentType<Scalar>::type OtherScalar;
  39. AlignedBox<OtherScalar,Dim> hp1f = b0.template cast<OtherScalar>();
  40. VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),b0);
  41. AlignedBox<Scalar,Dim> hp1d = b0.template cast<Scalar>();
  42. VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),b0);
  43. }
  44. void test_eigen2_alignedbox()
  45. {
  46. for(int i = 0; i < g_repeat; i++) {
  47. CALL_SUBTEST_1( alignedbox(AlignedBox<float,2>()) );
  48. CALL_SUBTEST_2( alignedbox(AlignedBox<float,3>()) );
  49. CALL_SUBTEST_3( alignedbox(AlignedBox<double,4>()) );
  50. }
  51. }