disjoint_coverage_p_p.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2017, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_TEST_MODULE
  8. #define BOOST_TEST_MODULE test_disjoint_coverage
  9. #endif
  10. // unit test to test disjoint for all geometry combinations
  11. #include <iostream>
  12. #include <boost/test/included/unit_test.hpp>
  13. #include <boost/geometry/core/tag.hpp>
  14. #include <boost/geometry/core/tags.hpp>
  15. #include <boost/geometry/strategies/strategies.hpp>
  16. #include <boost/geometry/io/wkt/wkt.hpp>
  17. #include <boost/geometry/io/dsv/write.hpp>
  18. #include <boost/geometry/geometries/geometries.hpp>
  19. #include <boost/geometry/algorithms/disjoint.hpp>
  20. #include <from_wkt.hpp>
  21. #ifdef HAVE_TTMATH
  22. #include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
  23. #endif
  24. namespace bg = ::boost::geometry;
  25. //============================================================================
  26. struct test_disjoint
  27. {
  28. template <typename Geometry1, typename Geometry2>
  29. static inline void apply(std::string const& case_id,
  30. Geometry1 const& geometry1,
  31. Geometry2 const& geometry2,
  32. bool expected_result)
  33. {
  34. bool result = bg::disjoint(geometry1, geometry2);
  35. BOOST_CHECK_MESSAGE(result == expected_result,
  36. "case ID: " << case_id << ", G1: " << bg::wkt(geometry1)
  37. << ", G2: " << bg::wkt(geometry2) << " -> Expected: "
  38. << expected_result << ", detected: " << result);
  39. result = bg::disjoint(geometry2, geometry1);
  40. BOOST_CHECK_MESSAGE(result == expected_result,
  41. "case ID: " << case_id << ", G1: " << bg::wkt(geometry2)
  42. << ", G2: " << bg::wkt(geometry1) << " -> Expected: "
  43. << expected_result << ", detected: " << result);
  44. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  45. std::cout << "case ID: " << case_id << "; G1 - G2: ";
  46. std::cout << bg::wkt(geometry1) << " - ";
  47. std::cout << bg::wkt(geometry2) << std::endl;
  48. std::cout << std::boolalpha;
  49. std::cout << "expected/computed result: "
  50. << expected_result << " / " << result << std::endl;
  51. std::cout << std::endl;
  52. std::cout << std::noboolalpha;
  53. #endif
  54. }
  55. };
  56. //============================================================================
  57. // pointlike-pointlike geometries
  58. template <typename P>
  59. inline void test_point_point()
  60. {
  61. typedef test_disjoint tester;
  62. tester::apply("p-p-01",
  63. from_wkt<P>("POINT(0 0)"),
  64. from_wkt<P>("POINT(0 0)"),
  65. false);
  66. tester::apply("p-p-02",
  67. from_wkt<P>("POINT(0 0)"),
  68. from_wkt<P>("POINT(1 1)"),
  69. true);
  70. }
  71. template <typename P>
  72. inline void test_point_multipoint()
  73. {
  74. typedef bg::model::multi_point<P> MP;
  75. typedef test_disjoint tester;
  76. tester::apply("p-mp-01",
  77. from_wkt<P>("POINT(0 0)"),
  78. from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
  79. false);
  80. tester::apply("p-mp-02",
  81. from_wkt<P>("POINT(0 0)"),
  82. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  83. true);
  84. tester::apply("p-mp-03",
  85. from_wkt<P>("POINT(0 0)"),
  86. from_wkt<MP>("MULTIPOINT()"),
  87. true);
  88. }
  89. template <typename P>
  90. inline void test_multipoint_point()
  91. {
  92. typedef bg::model::multi_point<P> MP;
  93. typedef test_disjoint tester;
  94. tester::apply("mp-p-01",
  95. from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
  96. from_wkt<P>("POINT(0 0)"),
  97. false);
  98. tester::apply("mp-p-02",
  99. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  100. from_wkt<P>("POINT(0 0)"),
  101. true);
  102. }
  103. template <typename P>
  104. inline void test_multipoint_multipoint()
  105. {
  106. typedef bg::model::multi_point<P> MP;
  107. typedef test_disjoint tester;
  108. tester::apply("mp-mp-01",
  109. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  110. from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
  111. false);
  112. tester::apply("mp-mp-02",
  113. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  114. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  115. true);
  116. tester::apply("mp-mp-03",
  117. from_wkt<MP>("MULTIPOINT()"),
  118. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  119. true);
  120. tester::apply("mp-mp-04",
  121. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  122. from_wkt<MP>("MULTIPOINT()"),
  123. true);
  124. }
  125. //============================================================================
  126. template <typename CoordinateType>
  127. inline void test_pointlike_pointlike()
  128. {
  129. typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
  130. test_point_point<point_type>();
  131. test_point_multipoint<point_type>();
  132. test_multipoint_point<point_type>();
  133. test_multipoint_multipoint<point_type>();
  134. }
  135. //============================================================================
  136. BOOST_AUTO_TEST_CASE( test_pointlike_pointlike_all )
  137. {
  138. test_pointlike_pointlike<double>();
  139. test_pointlike_pointlike<int>();
  140. #ifdef HAVE_TTMATH
  141. test_pointlike_pointlike<ttmath_big>();
  142. #endif
  143. }