disjoint_multi.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include "test_disjoint.hpp"
  8. #include <boost/geometry/strategies/strategies.hpp>
  9. #include <boost/geometry/geometries/geometries.hpp>
  10. #include <boost/geometry/geometries/point_xy.hpp>
  11. #include <test_common/test_point.hpp>
  12. #include <algorithms/predef_relop.hpp>
  13. template <typename P>
  14. void test_all()
  15. {
  16. typedef bg::model::linestring<P> ls;
  17. typedef bg::model::multi_linestring<ls> mls;
  18. typedef bg::model::polygon<P> polygon;
  19. typedef bg::model::multi_polygon<polygon> mp;
  20. test_disjoint<mp, mp>("",
  21. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  22. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  23. false);
  24. // True disjoint
  25. test_disjoint<mp, mp>("",
  26. "MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0)))",
  27. "MULTIPOLYGON(((6 6,6 10,10 10,10 6,6 6)))",
  28. true);
  29. // Touch -> not disjoint
  30. test_disjoint<mp, mp>("",
  31. "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)))",
  32. "MULTIPOLYGON(((5 5,5 10,10 10,10 5,5 5)))",
  33. false);
  34. // Not disjoint but no IP's
  35. test_disjoint<mp, mp>("no_ips",
  36. "MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))",
  37. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((22 2,28 2,28 8,22 8,22 2)))",
  38. false);
  39. // Not disjoint and not inside each other (in first ring) but wrapped (in second rings)
  40. test_disjoint<mp, mp>("no_ips2",
  41. "MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))",
  42. "MULTIPOLYGON(((2 12,2 18,8 18,8 12,2 12)),((22 2,28 2,28 8,22 8,22 2)))",
  43. false);
  44. test_disjoint<mp, mp>("no_ips2_rev",
  45. "MULTIPOLYGON(((2 12,2 18,8 18,8 12,2 12)),((22 2,28 2,28 8,22 8,22 2)))",
  46. "MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))",
  47. false);
  48. test_disjoint<P, mp>("point_mp1",
  49. "POINT(0 0)",
  50. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  51. false);
  52. test_disjoint<P, mp>("point_mp2",
  53. "POINT(5 5)",
  54. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  55. false);
  56. test_disjoint<P, mp>("point_mp1",
  57. "POINT(11 11)",
  58. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  59. true);
  60. std::string polygon_inside_hole("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0), (2 2,8 2,8 8,2 8,2 2)),((4 4,4 6,6 6,6 4,4 4)))");
  61. test_disjoint<P, mp>("point_mp_pih1",
  62. "POINT(5 5)",
  63. polygon_inside_hole,
  64. false);
  65. test_disjoint<P, mp>("point_mp_pih2",
  66. "POINT(3 3)",
  67. polygon_inside_hole,
  68. true);
  69. test_disjoint<mp, P>("point_mp1rev",
  70. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
  71. "POINT(0 0)",
  72. false);
  73. // assertion failure in 1.57
  74. test_disjoint<ls, mls>("point_l_ml_assert_1_57",
  75. "LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)",
  76. "MULTILINESTRING((20 100, 31 -97, -46 57, -20 -4))",
  77. false);
  78. test_disjoint<ls, mls>("point_l_ml_assert_1_57",
  79. "LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)",
  80. "MULTILINESTRING((20 100, 31 -97, -46 57, -20 -4),(-71 -4))",
  81. false);
  82. }
  83. int test_main(int, char* [])
  84. {
  85. //test_all<bg::model::d2::point_xy<float> >();
  86. test_all<bg::model::d2::point_xy<double> >();
  87. #ifdef HAVE_TTMATH
  88. test_all<bg::model::d2::point_xy<ttmath_big> >();
  89. #endif
  90. return 0;
  91. }
  92. /*
  93. with viewy as
  94. (
  95. select geometry::STGeomFromText('MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))',0) as p
  96. , geometry::STGeomFromText('MULTIPOLYGON(((2 12,2 18,8 18,8 12,2 12)),((22 2,28 2,28 8,22 8,22 2)))',0) as q
  97. )
  98. select p from viewy union all select q from viewy
  99. -- select p.STDisjoint(q) from viewy
  100. */