test_intersects.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
  5. // This file was modified by Oracle on 2017.
  6. // Modifications copyright (c) 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_INTERSECTS_HPP
  12. #define BOOST_GEOMETRY_TEST_INTERSECTS_HPP
  13. #include <geometry_test_common.hpp>
  14. #include <boost/geometry/core/geometry_id.hpp>
  15. #include <boost/geometry/core/point_order.hpp>
  16. #include <boost/geometry/core/ring_type.hpp>
  17. #include <boost/geometry/algorithms/covered_by.hpp>
  18. #include <boost/geometry/algorithms/intersects.hpp>
  19. #include <boost/geometry/strategies/strategies.hpp>
  20. #include <boost/geometry/geometries/ring.hpp>
  21. #include <boost/geometry/geometries/polygon.hpp>
  22. #include <boost/geometry/geometries/multi_linestring.hpp>
  23. #include <boost/geometry/geometries/multi_polygon.hpp>
  24. #include <boost/geometry/io/wkt/read.hpp>
  25. struct no_strategy {};
  26. template <typename Geometry1, typename Geometry2, typename Strategy>
  27. bool call_intersects(Geometry1 const& geometry1,
  28. Geometry2 const& geometry2,
  29. Strategy const& strategy)
  30. {
  31. return bg::intersects(geometry1, geometry2, strategy);
  32. }
  33. template <typename Geometry1, typename Geometry2>
  34. bool call_intersects(Geometry1 const& geometry1,
  35. Geometry2 const& geometry2,
  36. no_strategy)
  37. {
  38. return bg::intersects(geometry1, geometry2);
  39. }
  40. template <typename G1, typename G2, typename Strategy>
  41. void check_intersects(std::string const& wkt1,
  42. std::string const& wkt2,
  43. G1 const& g1,
  44. G2 const& g2,
  45. bool expected,
  46. Strategy const& strategy)
  47. {
  48. bool detected = call_intersects(g1, g2, strategy);
  49. BOOST_CHECK_MESSAGE(detected == expected,
  50. "intersects: " << wkt1
  51. << " with " << wkt2
  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, bool expected)
  58. {
  59. Geometry1 geometry1;
  60. Geometry2 geometry2;
  61. bg::read_wkt(wkt1, geometry1);
  62. bg::read_wkt(wkt2, geometry2);
  63. check_intersects(wkt1, wkt2, geometry1, geometry2, expected, no_strategy());
  64. check_intersects(wkt2, wkt1, geometry2, geometry1, expected, no_strategy());
  65. typedef typename bg::strategy::disjoint::services::default_strategy
  66. <
  67. Geometry1, Geometry2
  68. >::type strategy12_type;
  69. typedef typename bg::strategy::disjoint::services::default_strategy
  70. <
  71. Geometry2, Geometry1
  72. >::type strategy21_type;
  73. check_intersects(wkt1, wkt2, geometry1, geometry2, expected, strategy12_type());
  74. check_intersects(wkt2, wkt1, geometry2, geometry1, expected, strategy21_type());
  75. }
  76. template <typename Geometry>
  77. void test_self_intersects(std::string const& wkt, bool expected)
  78. {
  79. Geometry geometry;
  80. bg::read_wkt(wkt, geometry);
  81. bool detected = bg::intersects(geometry);
  82. BOOST_CHECK_MESSAGE(detected == expected,
  83. "intersects: " << wkt
  84. << " -> Expected: " << expected
  85. << " detected: " << detected);
  86. }
  87. #endif