test_length.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2016 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_TEST_LENGTH_HPP
  10. #define BOOST_GEOMETRY_TEST_LENGTH_HPP
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/algorithms/length.hpp>
  13. #include <boost/geometry/io/wkt/wkt.hpp>
  14. #include <boost/geometry/strategies/strategies.hpp>
  15. #include <boost/variant/variant.hpp>
  16. template <typename Geometry>
  17. void test_length(Geometry const& geometry, long double expected_length)
  18. {
  19. typename bg::default_length_result<Geometry>::type
  20. length = bg::length(geometry);
  21. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  22. std::ostringstream out;
  23. out << typeid(typename bg::coordinate_type<Geometry>::type).name()
  24. << std::endl
  25. << typeid(typename bg::default_length_result<Geometry>::type).name()
  26. << std::endl
  27. << "length : " << bg::length(geometry)
  28. << std::endl;
  29. std::cout << out.str();
  30. #endif
  31. BOOST_CHECK_CLOSE(length, expected_length, 0.0001);
  32. }
  33. template <typename Geometry, typename Strategy>
  34. void test_length(Geometry const& geometry, long double expected_length, Strategy strategy)
  35. {
  36. typename bg::default_length_result<Geometry>::type
  37. length = bg::length(geometry, strategy);
  38. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  39. std::ostringstream out;
  40. out << typeid(typename bg::coordinate_type<Geometry>::type).name()
  41. << std::endl
  42. << typeid(typename bg::default_length_result<Geometry>::type).name()
  43. << std::endl
  44. << "length : " << bg::length(geometry, strategy)
  45. << std::endl;
  46. std::cout << out.str();
  47. #endif
  48. BOOST_CHECK_CLOSE(length, expected_length, 0.0001);
  49. }
  50. template <typename Geometry>
  51. void test_geometry(std::string const& wkt, double expected_length)
  52. {
  53. Geometry geometry;
  54. bg::read_wkt(wkt, geometry);
  55. test_length(geometry, expected_length);
  56. #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
  57. test_length(boost::variant<Geometry>(geometry), expected_length);
  58. #endif
  59. }
  60. template <typename Geometry, typename Strategy>
  61. void test_geometry(std::string const& wkt, double expected_length, Strategy strategy)
  62. {
  63. Geometry geometry;
  64. bg::read_wkt(wkt, geometry);
  65. test_length(geometry, expected_length, strategy);
  66. #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
  67. test_length(boost::variant<Geometry>(geometry), expected_length, strategy);
  68. #endif
  69. }
  70. template <typename Geometry>
  71. void test_empty_input(Geometry const& geometry)
  72. {
  73. try
  74. {
  75. bg::length(geometry);
  76. }
  77. catch(bg::empty_input_exception const& )
  78. {
  79. return;
  80. }
  81. BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
  82. }
  83. #endif