test_equals.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2014-2017 Adam Wulkiewicz, Lodz, Poland.
  5. // This file was modified by Oracle on 2016-2017.
  6. // Modifications copyright (c) 2016-2017 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_EQUALS_HPP
  12. #define BOOST_GEOMETRY_TEST_EQUALS_HPP
  13. #include <geometry_test_common.hpp>
  14. #include <boost/geometry/core/ring_type.hpp>
  15. #include <boost/geometry/algorithms/correct.hpp>
  16. #include <boost/geometry/algorithms/equals.hpp>
  17. #include <boost/geometry/strategies/strategies.hpp>
  18. #include <boost/geometry/io/wkt/read.hpp>
  19. #include <boost/variant/variant.hpp>
  20. struct no_strategy {};
  21. template <typename Geometry1, typename Geometry2, typename Strategy>
  22. bool call_equals(Geometry1 const& geometry1,
  23. Geometry2 const& geometry2,
  24. Strategy const& strategy)
  25. {
  26. return bg::equals(geometry1, geometry2, strategy);
  27. }
  28. template <typename Geometry1, typename Geometry2>
  29. bool call_equals(Geometry1 const& geometry1,
  30. Geometry2 const& geometry2,
  31. no_strategy)
  32. {
  33. return bg::equals(geometry1, geometry2);
  34. }
  35. template <typename Geometry1, typename Geometry2, typename Strategy>
  36. void check_geometry(Geometry1 const& geometry1,
  37. Geometry2 const& geometry2,
  38. std::string const& caseid,
  39. std::string const& wkt1,
  40. std::string const& wkt2,
  41. bool expected,
  42. Strategy const& strategy)
  43. {
  44. bool detected = call_equals(geometry1, geometry2, strategy);
  45. BOOST_CHECK_MESSAGE(detected == expected,
  46. "case: " << caseid
  47. << " equals: " << wkt1
  48. << " to " << wkt2
  49. << " -> Expected: " << expected
  50. << " detected: " << detected);
  51. detected = call_equals(geometry2, geometry1, strategy);
  52. BOOST_CHECK_MESSAGE(detected == expected,
  53. "case: " << caseid
  54. << " equals: " << wkt2
  55. << " to " << wkt1
  56. << " -> Expected: " << expected
  57. << " detected: " << detected);
  58. }
  59. template <typename Geometry1, typename Geometry2>
  60. void test_geometry(std::string const& caseid,
  61. std::string const& wkt1,
  62. std::string const& wkt2,
  63. bool expected,
  64. bool correct_geometries = false)
  65. {
  66. Geometry1 geometry1;
  67. Geometry2 geometry2;
  68. bg::read_wkt(wkt1, geometry1);
  69. bg::read_wkt(wkt2, geometry2);
  70. if (correct_geometries)
  71. {
  72. bg::correct(geometry1);
  73. bg::correct(geometry2);
  74. }
  75. typedef typename bg::strategy::relate::services::default_strategy
  76. <
  77. Geometry1, Geometry2
  78. >::type strategy_type;
  79. check_geometry(geometry1, geometry2, caseid, wkt1, wkt2, expected, no_strategy());
  80. check_geometry(geometry1, geometry2, caseid, wkt1, wkt2, expected, strategy_type());
  81. check_geometry(boost::variant<Geometry1>(geometry1), geometry2, caseid, wkt1, wkt2, expected, no_strategy());
  82. check_geometry(geometry1, boost::variant<Geometry2>(geometry2), caseid, wkt1, wkt2, expected, no_strategy());
  83. check_geometry(boost::variant<Geometry1>(geometry1), boost::variant<Geometry2>(geometry2), caseid, wkt1, wkt2, expected, no_strategy());
  84. }
  85. template <typename Geometry1, typename Geometry2>
  86. void test_geometry(std::string const& wkt1,
  87. std::string const& wkt2,
  88. bool expected)
  89. {
  90. test_geometry<Geometry1, Geometry2>("", wkt1, wkt2, expected);
  91. }
  92. #endif