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.

62 lines
2.3 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. // 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. #include "main.h"
  11. #include <Eigen/Geometry>
  12. #include <Eigen/LU>
  13. #include <Eigen/QR>
  14. template<typename LineType> void parametrizedline(const LineType& _line)
  15. {
  16. /* this test covers the following files:
  17. ParametrizedLine.h
  18. */
  19. const int dim = _line.dim();
  20. typedef typename LineType::Scalar Scalar;
  21. typedef typename NumTraits<Scalar>::Real RealScalar;
  22. typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime, 1> VectorType;
  23. typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime,
  24. LineType::AmbientDimAtCompileTime> MatrixType;
  25. VectorType p0 = VectorType::Random(dim);
  26. VectorType p1 = VectorType::Random(dim);
  27. VectorType d0 = VectorType::Random(dim).normalized();
  28. LineType l0(p0, d0);
  29. Scalar s0 = ei_random<Scalar>();
  30. Scalar s1 = ei_abs(ei_random<Scalar>());
  31. VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0), RealScalar(1) );
  32. VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(p0+s0*d0), RealScalar(1) );
  33. VERIFY_IS_APPROX( (l0.projection(p1)-p1).norm(), l0.distance(p1) );
  34. VERIFY_IS_MUCH_SMALLER_THAN( l0.distance(l0.projection(p1)), RealScalar(1) );
  35. VERIFY_IS_APPROX( Scalar(l0.distance((p0+s0*d0) + d0.unitOrthogonal() * s1)), s1 );
  36. // casting
  37. const int Dim = LineType::AmbientDimAtCompileTime;
  38. typedef typename GetDifferentType<Scalar>::type OtherScalar;
  39. ParametrizedLine<OtherScalar,Dim> hp1f = l0.template cast<OtherScalar>();
  40. VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),l0);
  41. ParametrizedLine<Scalar,Dim> hp1d = l0.template cast<Scalar>();
  42. VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),l0);
  43. }
  44. void test_eigen2_parametrizedline()
  45. {
  46. for(int i = 0; i < g_repeat; i++) {
  47. CALL_SUBTEST_1( parametrizedline(ParametrizedLine<float,2>()) );
  48. CALL_SUBTEST_2( parametrizedline(ParametrizedLine<float,3>()) );
  49. CALL_SUBTEST_3( parametrizedline(ParametrizedLine<double,4>()) );
  50. CALL_SUBTEST_4( parametrizedline(ParametrizedLine<std::complex<double>,5>()) );
  51. }
  52. }