test_touches.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2013, 2015, 2016, 2017.
  5. // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_TEST_TOUCHES_HPP
  11. #define BOOST_GEOMETRY_TEST_TOUCHES_HPP
  12. #include <geometry_test_common.hpp>
  13. #include <boost/geometry/core/ring_type.hpp>
  14. #include <boost/geometry/algorithms/touches.hpp>
  15. #include <boost/geometry/strategies/strategies.hpp>
  16. #include <boost/geometry/geometries/geometries.hpp>
  17. #include <boost/geometry/geometries/point_xy.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. void check_touches(Geometry1 const& geometry1,
  23. Geometry2 const& geometry2,
  24. std::string const& wkt1,
  25. std::string const& wkt2,
  26. bool expected,
  27. Strategy const& strategy)
  28. {
  29. bool detected = bg::touches(geometry1, geometry2, strategy);
  30. BOOST_CHECK_MESSAGE(detected == expected,
  31. "touches: " << wkt1
  32. << " with " << wkt2
  33. << " -> Expected: " << expected
  34. << " detected: " << detected);
  35. detected = bg::touches(geometry2, geometry1, strategy);
  36. BOOST_CHECK_MESSAGE(detected == expected,
  37. "touches: " << wkt2
  38. << " with " << wkt1
  39. << " -> Expected: " << expected
  40. << " detected: " << detected);
  41. }
  42. template <typename Geometry1, typename Geometry2>
  43. void check_touches(Geometry1 const& geometry1,
  44. Geometry2 const& geometry2,
  45. std::string const& wkt1,
  46. std::string const& wkt2,
  47. bool expected,
  48. no_strategy = no_strategy())
  49. {
  50. bool detected = bg::touches(geometry1, geometry2);
  51. BOOST_CHECK_MESSAGE(detected == expected,
  52. "touches: " << wkt1
  53. << " with " << wkt2
  54. << " -> Expected: " << expected
  55. << " detected: " << detected);
  56. detected = bg::touches(geometry2, geometry1);
  57. BOOST_CHECK_MESSAGE(detected == expected,
  58. "touches: " << wkt2
  59. << " with " << wkt1
  60. << " -> Expected: " << expected
  61. << " detected: " << detected);
  62. }
  63. template <typename Geometry1, typename Geometry2>
  64. void test_touches(std::string const& wkt1,
  65. std::string const& wkt2, bool expected)
  66. {
  67. Geometry1 geometry1;
  68. Geometry2 geometry2;
  69. bg::read_wkt(wkt1, geometry1);
  70. bg::read_wkt(wkt2, geometry2);
  71. boost::variant<Geometry1> v1(geometry1);
  72. boost::variant<Geometry2> v2(geometry2);
  73. typedef typename bg::strategy::relate::services::default_strategy
  74. <
  75. Geometry1, Geometry2
  76. >::type strategy_type;
  77. check_touches(geometry1, geometry2, wkt1, wkt2, expected, no_strategy());
  78. check_touches(geometry1, geometry2, wkt1, wkt2, expected, strategy_type());
  79. check_touches(v1, geometry2, wkt1, wkt2, expected, no_strategy());
  80. check_touches(geometry1, v2, wkt1, wkt2, expected, no_strategy());
  81. check_touches(v1, v2, wkt1, wkt2, expected, no_strategy());
  82. }
  83. template <typename Geometry1, typename Geometry2>
  84. void test_geometry(std::string const& wkt1,
  85. std::string const& wkt2,
  86. bool expected)
  87. {
  88. test_touches<Geometry1, Geometry2>(wkt1, wkt2, expected);
  89. }
  90. template <typename Geometry>
  91. void check_self_touches(Geometry const& geometry,
  92. std::string const& wkt,
  93. bool expected)
  94. {
  95. bool detected = bg::touches(geometry);
  96. BOOST_CHECK_MESSAGE(detected == expected,
  97. "touches: " << wkt
  98. << " -> Expected: " << expected
  99. << " detected: " << detected);
  100. }
  101. template <typename Geometry>
  102. void test_self_touches(std::string const& wkt, bool expected)
  103. {
  104. Geometry geometry;
  105. bg::read_wkt(wkt, geometry);
  106. boost::variant<Geometry> v(geometry);
  107. check_self_touches(geometry, wkt, expected);
  108. check_self_touches(v, wkt, expected);
  109. }
  110. #endif