test_crosses.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 2014, 2017.
  5. // Modifications copyright (c) 2014-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_CROSSES_HPP
  11. #define BOOST_GEOMETRY_TEST_CROSSES_HPP
  12. #include <geometry_test_common.hpp>
  13. #include <boost/geometry/core/ring_type.hpp>
  14. #include <boost/geometry/algorithms/crosses.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. bool call_crosses(Geometry1 const& geometry1,
  23. Geometry2 const& geometry2,
  24. Strategy const& strategy)
  25. {
  26. return bg::crosses(geometry1, geometry2, strategy);
  27. }
  28. template <typename Geometry1, typename Geometry2>
  29. bool call_crosses(Geometry1 const& geometry1,
  30. Geometry2 const& geometry2,
  31. no_strategy)
  32. {
  33. return bg::crosses(geometry1, geometry2);
  34. }
  35. template <typename Geometry1, typename Geometry2>
  36. void test_geometry(std::string const& wkt1,
  37. std::string const& wkt2, bool expected)
  38. {
  39. Geometry1 geometry1;
  40. Geometry2 geometry2;
  41. bg::read_wkt(wkt1, geometry1);
  42. bg::read_wkt(wkt2, geometry2);
  43. bool detected = call_crosses(geometry1, geometry2, no_strategy());
  44. BOOST_CHECK_MESSAGE(detected == expected,
  45. "crosses: " << wkt1
  46. << " with " << wkt2
  47. << " -> Expected: " << expected
  48. << " detected: " << detected);
  49. typedef typename bg::strategy::relate::services::default_strategy
  50. <
  51. Geometry1, Geometry2
  52. >::type strategy_type;
  53. detected = call_crosses(geometry1, geometry2, strategy_type());
  54. BOOST_CHECK_MESSAGE(detected == expected,
  55. "crosses: " << wkt1
  56. << " with " << wkt2
  57. << " -> Expected: " << expected
  58. << " detected: " << detected);
  59. #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
  60. detected = bg::crosses(geometry1,
  61. boost::variant<Geometry2>(geometry2));
  62. BOOST_CHECK_MESSAGE(detected == expected,
  63. "crosses: " << wkt1
  64. << " with " << wkt2
  65. << " -> Expected: " << expected
  66. << " detected: " << detected);
  67. detected = bg::crosses(boost::variant<Geometry1>(geometry1),
  68. geometry2);
  69. BOOST_CHECK_MESSAGE(detected == expected,
  70. "crosses: " << wkt1
  71. << " with " << wkt2
  72. << " -> Expected: " << expected
  73. << " detected: " << detected);
  74. detected = bg::crosses(boost::variant<Geometry1>(geometry1),
  75. boost::variant<Geometry2>(geometry2));
  76. BOOST_CHECK_MESSAGE(detected == expected,
  77. "crosses: " << wkt1
  78. << " with " << wkt2
  79. << " -> Expected: " << expected
  80. << " detected: " << detected);
  81. #endif
  82. }
  83. #endif // BOOST_GEOMETRY_TEST_CROSSES_HPP