test_hausdorff_distance.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Boost.Geometry
  2. // Copyright (c) 2018 Yaghyavardhan Singh Khangarot, Hyderabad, India.
  3. // Contributed and/or modified by Yaghyavardhan Singh Khangarot,
  4. // as part of Google Summer of Code 2018 program.
  5. // This file was modified by Oracle on 2018.
  6. // Modifications copyright (c) 2018, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_TEST_HAUSDORFF_DISTANCE_HPP
  12. #define BOOST_GEOMETRY_TEST_HAUSDORFF_DISTANCE_HPP
  13. #include <geometry_test_common.hpp>
  14. #include <boost/geometry/algorithms/discrete_hausdorff_distance.hpp>
  15. #include <boost/geometry/io/wkt/wkt.hpp>
  16. #include <boost/geometry/strategies/strategies.hpp>
  17. #include <boost/variant/variant.hpp>
  18. template <typename Geometry1, typename Geometry2, typename Expected>
  19. void test_hausdorff_distance(Geometry1 const& geometry1, Geometry2 const& geometry2,
  20. Expected const& expected_hausdorff_distance)
  21. {
  22. typedef typename bg::distance_result
  23. <
  24. typename bg::point_type<Geometry1>::type,
  25. typename bg::point_type<Geometry2>::type
  26. >::type result_type;
  27. result_type h_distance = bg::discrete_hausdorff_distance(geometry1, geometry2);
  28. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  29. std::ostringstream out;
  30. out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
  31. << std::endl
  32. << typeid(typename bg::coordinate_type<Geometry2>::type).name()
  33. << std::endl
  34. << typeid(h_distance).name()
  35. << std::endl
  36. << "hausdorff_distance : " << h_distance
  37. << std::endl;
  38. std::cout << out.str();
  39. #endif
  40. BOOST_CHECK_CLOSE(h_distance, result_type(expected_hausdorff_distance), 0.01);
  41. }
  42. template <typename Geometry1, typename Geometry2, typename Expected>
  43. void test_geometry(std::string const& wkt1, std::string const& wkt2,
  44. Expected const& expected_hausdorff_distance)
  45. {
  46. Geometry1 geometry1;
  47. bg::read_wkt(wkt1, geometry1);
  48. Geometry2 geometry2;
  49. bg::read_wkt(wkt2, geometry2);
  50. test_hausdorff_distance(geometry1, geometry2, expected_hausdorff_distance);
  51. #if defined(BOOST_GEOMETRY_TEST_DEBUG)
  52. test_hausdorff_distance(boost::variant<Geometry1>(geometry1),
  53. boost::variant<Geometry2>(geometry2),
  54. expected_hausdorff_distance);
  55. #endif
  56. }
  57. template <typename Geometry1, typename Geometry2, typename Strategy, typename Expected>
  58. void test_hausdorff_distance(Geometry1 const& geometry1, Geometry2 const& geometry2,
  59. Strategy strategy, Expected const& expected_hausdorff_distance)
  60. {
  61. typedef typename bg::distance_result
  62. <
  63. typename bg::point_type<Geometry1>::type,
  64. typename bg::point_type<Geometry2>::type,
  65. Strategy
  66. >::type result_type;
  67. result_type h_distance = bg::discrete_hausdorff_distance(geometry1, geometry2, strategy);
  68. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  69. std::ostringstream out;
  70. out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
  71. << std::endl
  72. << typeid(typename bg::coordinate_type<Geometry2>::type).name()
  73. << std::endl
  74. << typeid(h_distance).name()
  75. << std::endl
  76. << "hausdorff_distance : " << h_distance
  77. << std::endl;
  78. std::cout << out.str();
  79. #endif
  80. BOOST_CHECK_CLOSE(h_distance, result_type(expected_hausdorff_distance), 0.01);
  81. }
  82. template <typename Geometry1, typename Geometry2, typename Strategy, typename Expected>
  83. void test_geometry(std::string const& wkt1, std::string const& wkt2,
  84. Strategy strategy, Expected const& expected_hausdorff_distance)
  85. {
  86. Geometry1 geometry1;
  87. bg::read_wkt(wkt1, geometry1);
  88. Geometry2 geometry2;
  89. bg::read_wkt(wkt2, geometry2);
  90. test_hausdorff_distance(geometry1, geometry2, strategy, expected_hausdorff_distance);
  91. #if defined(BOOST_GEOMETRY_TEST_DEBUG)
  92. test_hausdorff_distance(boost::variant<Geometry1>(geometry1),
  93. boost::variant<Geometry2>(geometry2),
  94. strategy, expected_hausdorff_distance);
  95. #endif
  96. }
  97. template <typename Geometry1,typename Geometry2>
  98. void test_empty_input(Geometry1 const& geometry1, Geometry2 const& geometry2)
  99. {
  100. try
  101. {
  102. bg::discrete_hausdorff_distance(geometry1, geometry2);
  103. }
  104. catch(bg::empty_input_exception const& )
  105. {
  106. return;
  107. }
  108. BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown");
  109. }
  110. #endif