test_disjoint.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2017.
  7. // Modifications copyright (c) 2017 Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_TEST_DISJOINT_HPP
  15. #define BOOST_GEOMETRY_TEST_DISJOINT_HPP
  16. #include <iostream>
  17. #include <string>
  18. #include <boost/variant/variant.hpp>
  19. #include <geometry_test_common.hpp>
  20. #include <boost/geometry/algorithms/disjoint.hpp>
  21. #include <boost/geometry/io/wkt/read.hpp>
  22. struct no_strategy {};
  23. template <typename Geometry1, typename Geometry2, typename Strategy>
  24. bool call_disjoint(Geometry1 const& geometry1,
  25. Geometry2 const& geometry2,
  26. Strategy const& strategy)
  27. {
  28. return bg::disjoint(geometry1, geometry2, strategy);
  29. }
  30. template <typename Geometry1, typename Geometry2>
  31. bool call_disjoint(Geometry1 const& geometry1,
  32. Geometry2 const& geometry2,
  33. no_strategy)
  34. {
  35. return bg::disjoint(geometry1, geometry2);
  36. }
  37. template <typename G1, typename G2, typename Strategy>
  38. void check_disjoint(std::string const& id,
  39. std::string const& wkt1,
  40. std::string const& wkt2,
  41. G1 const& g1,
  42. G2 const& g2,
  43. bool expected,
  44. Strategy const& strategy)
  45. {
  46. bool detected = call_disjoint(g1, g2, strategy);
  47. if (id.empty())
  48. {
  49. BOOST_CHECK_MESSAGE(detected == expected,
  50. "disjoint: " << wkt1 << " and " << wkt2
  51. << " -> Expected: " << expected
  52. << " detected: " << detected);
  53. }
  54. else
  55. {
  56. BOOST_CHECK_MESSAGE(detected == expected,
  57. "disjoint: " << id
  58. << " -> Expected: " << expected
  59. << " detected: " << detected);
  60. }
  61. }
  62. template <typename G1, typename G2>
  63. void test_disjoint(std::string const& id,
  64. std::string const& wkt1,
  65. std::string const& wkt2,
  66. bool expected)
  67. {
  68. G1 g1;
  69. bg::read_wkt(wkt1, g1);
  70. G2 g2;
  71. bg::read_wkt(wkt2, g2);
  72. boost::variant<G1> v1(g1);
  73. boost::variant<G2> v2(g2);
  74. typedef typename bg::strategy::disjoint::services::default_strategy
  75. <
  76. G1, G2
  77. >::type strategy_type;
  78. check_disjoint(id, wkt1, wkt2, g1, g2, expected, no_strategy());
  79. check_disjoint(id, wkt1, wkt2, g1, g2, expected, strategy_type());
  80. check_disjoint(id, wkt1, wkt2, g1, g2, expected, no_strategy());
  81. check_disjoint(id, wkt1, wkt2, v1, g2, expected, no_strategy());
  82. check_disjoint(id, wkt1, wkt2, g1, v2, expected, no_strategy());
  83. check_disjoint(id, wkt1, wkt2, v1, v2, expected, no_strategy());
  84. }
  85. template <typename G1, typename G2>
  86. void test_geometry(std::string const& wkt1,
  87. std::string const& wkt2,
  88. bool expected)
  89. {
  90. test_disjoint<G1, G2>("", wkt1, wkt2, expected);
  91. }
  92. #endif // BOOST_GEOMETRY_TEST_DISJOINT_HPP