test_overlaps.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Generic Geometry2 Library
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2015, 2017.
  5. // Modifications copyright (c) 2015-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_OVERLAPS_HPP
  11. #define BOOST_GEOMETRY_TEST_OVERLAPS_HPP
  12. #include <geometry_test_common.hpp>
  13. #include <boost/geometry/core/ring_type.hpp>
  14. #include <boost/geometry/algorithms/overlaps.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. struct no_strategy {};
  20. template <typename Geometry1, typename Geometry2, typename Strategy>
  21. bool call_overlaps(Geometry1 const& geometry1,
  22. Geometry2 const& geometry2,
  23. Strategy const& strategy)
  24. {
  25. return bg::overlaps(geometry1, geometry2, strategy);
  26. }
  27. template <typename Geometry1, typename Geometry2>
  28. bool call_overlaps(Geometry1 const& geometry1,
  29. Geometry2 const& geometry2,
  30. no_strategy)
  31. {
  32. return bg::overlaps(geometry1, geometry2);
  33. }
  34. template <typename Geometry1, typename Geometry2, typename Strategy>
  35. void test_geometry(Geometry1 const& geometry1,
  36. Geometry2 const& geometry2,
  37. std::string const& wkt1,
  38. std::string const& wkt2,
  39. bool expected,
  40. Strategy const& strategy)
  41. {
  42. bool detected = call_overlaps(geometry1, geometry2, strategy);
  43. BOOST_CHECK_MESSAGE(detected == expected,
  44. "overlaps: " << wkt1
  45. << " with " << wkt2
  46. << " -> Expected: " << expected
  47. << " detected: " << detected);
  48. detected = call_overlaps(geometry2, geometry1, strategy);
  49. BOOST_CHECK_MESSAGE(detected == expected,
  50. "overlaps: " << wkt2
  51. << " with " << wkt1
  52. << " -> Expected: " << expected
  53. << " detected: " << detected);
  54. }
  55. template <typename Geometry1, typename Geometry2>
  56. void test_geometry(std::string const& wkt1,
  57. std::string const& wkt2,
  58. bool expected)
  59. {
  60. Geometry1 geometry1;
  61. Geometry2 geometry2;
  62. bg::read_wkt(wkt1, geometry1);
  63. bg::read_wkt(wkt2, geometry2);
  64. test_geometry(geometry1, geometry2, wkt1, wkt2, expected, no_strategy());
  65. typedef typename bg::strategy::relate::services::default_strategy
  66. <
  67. Geometry1, Geometry2
  68. >::type strategy_type;
  69. test_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy_type());
  70. }
  71. #endif