test_perimeter.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_TEST_PERIMETER_HPP
  8. #define BOOST_GEOMETRY_TEST_PERIMETER_HPP
  9. #include <boost/variant/variant.hpp>
  10. #include <geometry_test_common.hpp>
  11. #include <boost/geometry/algorithms/perimeter.hpp>
  12. #include <boost/geometry/strategies/strategies.hpp>
  13. #include <boost/geometry/io/wkt/read.hpp>
  14. template <typename Geometry>
  15. void test_perimeter(Geometry const& geometry, long double expected_perimeter)
  16. {
  17. typename bg::default_length_result<Geometry>::type
  18. perimeter = bg::perimeter(geometry);
  19. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  20. std::ostringstream out;
  21. out << typeid(typename bg::coordinate_type<Geometry>::type).name()
  22. << std::endl
  23. //<< typeid(typename bg::default_perimeter_result<Geometry>::type).name()
  24. << std::endl
  25. << "perimeter : " << bg::perimeter(geometry)
  26. << std::endl;
  27. std::cout << out.str();
  28. #endif
  29. BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
  30. }
  31. template <typename Geometry, typename Strategy>
  32. void test_perimeter(Geometry const& geometry, long double expected_perimeter, Strategy strategy)
  33. {
  34. typename bg::default_length_result<Geometry>::type
  35. perimeter = bg::perimeter(geometry, strategy);
  36. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  37. std::ostringstream out;
  38. out << typeid(typename bg::coordinate_type<Geometry>::type).name()
  39. << std::endl
  40. //<< typeid(typename bg::default_perimeter_result<Geometry>::type).name()
  41. << std::endl
  42. << "perimeter : " << bg::perimeter(geometry, strategy)
  43. << std::endl;
  44. std::cout << out.str();
  45. #endif
  46. BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
  47. }
  48. template <typename Geometry>
  49. void test_geometry(std::string const& wkt, double expected_perimeter)
  50. {
  51. Geometry geometry;
  52. bg::read_wkt(wkt, geometry);
  53. boost::variant<Geometry> v(geometry);
  54. test_perimeter(geometry, expected_perimeter);
  55. #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
  56. test_perimeter(v, expected_perimeter);
  57. #endif
  58. }
  59. template <typename Geometry, typename Strategy>
  60. void test_geometry(std::string const& wkt, double expected_perimeter, Strategy strategy)
  61. {
  62. Geometry geometry;
  63. bg::read_wkt(wkt, geometry);
  64. boost::variant<Geometry> v(geometry);
  65. test_perimeter(geometry, expected_perimeter, strategy);
  66. #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
  67. test_perimeter(v, expected_perimeter, strategy);
  68. #endif
  69. }
  70. template <typename Geometry>
  71. void test_empty_input(Geometry const& geometry)
  72. {
  73. try
  74. {
  75. bg::perimeter(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