disjoint.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 2015.
  7. // Modifications copyright (c) 2015, 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. #include "test_disjoint.hpp"
  15. #include <boost/geometry/geometries/geometries.hpp>
  16. #include <boost/geometry/geometries/point_xy.hpp>
  17. #include <boost/geometry/strategies/strategies.hpp>
  18. #include <test_common/test_point.hpp>
  19. #include <algorithms/overlay/overlay_cases.hpp>
  20. #include <algorithms/predef_relop.hpp>
  21. template <typename P>
  22. void test_all()
  23. {
  24. // Test triangles for polygons/rings, boxes
  25. // Note that intersections are tested elsewhere, they don't need
  26. // thorough test at this place
  27. typedef bg::model::polygon<P> polygon;
  28. typedef bg::model::ring<P> ring;
  29. // Four times same test with other types
  30. test_disjoint<polygon, polygon>("disjoint_simplex_pp", disjoint_simplex[0], disjoint_simplex[1], true);
  31. test_disjoint<ring, polygon>("disjoint_simplex_rp", disjoint_simplex[0], disjoint_simplex[1], true);
  32. test_disjoint<ring, ring>("disjoint_simplex_rr", disjoint_simplex[0], disjoint_simplex[1], true);
  33. test_disjoint<polygon, ring>("disjoint_simplex_pr", disjoint_simplex[0], disjoint_simplex[1], true);
  34. test_disjoint<polygon, polygon>("ticket_8310a", ticket_8310a[0], ticket_8310a[1], false);
  35. test_disjoint<polygon, polygon>("ticket_8310b", ticket_8310b[0], ticket_8310b[1], false);
  36. test_disjoint<polygon, polygon>("ticket_8310c", ticket_8310c[0], ticket_8310c[1], false);
  37. // Testing touch
  38. test_disjoint<polygon, polygon>("touch_simplex_pp", touch_simplex[0], touch_simplex[1], false);
  39. // Test if within(a,b) returns false for disjoint
  40. test_disjoint<ring, ring>("within_simplex_rr1", within_simplex[0], within_simplex[1], false);
  41. test_disjoint<ring, ring>("within_simplex_rr2", within_simplex[1], within_simplex[0], false);
  42. // Linear
  43. typedef bg::model::linestring<P> ls;
  44. typedef bg::model::segment<P> segment;
  45. test_disjoint<ls, ls>("ls/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  46. test_disjoint<ls, ls>("ls/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  47. test_disjoint<segment, segment>("s/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  48. test_disjoint<segment, segment>("s/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  49. // Test degenerate segments (patched by Karsten Ahnert on 2012-07-25)
  50. test_disjoint<segment, segment>("s/s 3", "linestring(0 0,0 0)", "linestring(1 0,0 1)", true);
  51. test_disjoint<segment, segment>("s/s 4", "linestring(0 0,0 0)", "linestring(0 0,0 0)", false);
  52. test_disjoint<segment, segment>("s/s 5", "linestring(0 0,0 0)", "linestring(1 0,1 0)", true);
  53. test_disjoint<segment, segment>("s/s 6", "linestring(0 0,0 0)", "linestring(0 1,0 1)", true);
  54. // Collinear opposite
  55. test_disjoint<ls, ls>("ls/ls co", "linestring(0 0,2 2)", "linestring(1 1,0 0)", false);
  56. // Collinear opposite and equal
  57. test_disjoint<ls, ls>("ls/ls co-e", "linestring(0 0,1 1)", "linestring(1 1,0 0)", false);
  58. // Degenerate linestrings
  59. {
  60. // Submitted by Zachary on the Boost.Geometry Mailing List, on 2012-01-29
  61. std::string const a = "linestring(100 10, 0 10)";
  62. std::string const b = "linestring(50 10, 50 10)"; // one point only, with same y-coordinate
  63. std::string const c = "linestring(100 10, 100 10)"; // idem, at left side
  64. test_disjoint<ls, ls>("dls/dls 1", a, b, false);
  65. test_disjoint<ls, ls>("dls/dls 2", b, a, false);
  66. test_disjoint<segment, segment>("ds/ds 1", a, b, false);
  67. test_disjoint<segment, segment>("ds/ds 2", b, a, false);
  68. test_disjoint<ls, ls>("dls/dls 1", a, c, false);
  69. }
  70. // Linestrings making angles normally ignored
  71. {
  72. // These (non-disjoint) cases
  73. // correspond to the test "segment_intersection_collinear"
  74. // Collinear ('a')
  75. // a1---------->a2
  76. // b1--->b2
  77. test_disjoint<ls, ls>("n1", "linestring(2 0,0 6)", "linestring(0 0,2 0)", false);
  78. // a1---------->a2
  79. // b1--->b2
  80. test_disjoint<ls, ls>("n7", "linestring(2 0,6 0)", "linestring(6 0,8 0)", false);
  81. // Collinear - opposite ('f')
  82. // a1---------->a2
  83. // b2<---b1
  84. test_disjoint<ls, ls>("o1", "linestring(2 0,6 0)", "linestring(2 0,0 0)", false);
  85. }
  86. {
  87. // Starting in the middle ('s')
  88. // b2
  89. // ^
  90. // |
  91. // |
  92. // a1--------b1----->a2
  93. test_disjoint<ls, ls>("case_s", "linestring(0 0,4 0)", "linestring(2 0,2 2)", false);
  94. // Collinear, but disjoint
  95. test_disjoint<ls, ls>("c-d", "linestring(2 0,6 0)", "linestring(7 0,8 0)", true);
  96. // Parallel, disjoint
  97. test_disjoint<ls, ls>("c-d", "linestring(2 0,6 0)", "linestring(2 1,6 1)", true);
  98. // Error still there until 1.48 (reported "error", was reported to disjoint, so that's why it did no harm)
  99. test_disjoint<ls, ls>("case_recursive_boxes_1",
  100. "linestring(10 7,10 6)", "linestring(10 10,10 9)", true);
  101. }
  102. // TODO test_disjoint<segment, ls>("s/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  103. // TODO test_disjoint<segment, ls>("s/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  104. // TODO test_disjoint<ls, segment>("ls/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  105. // TODO test_disjoint<ls, segment>("ls/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  106. // 22.01.2015
  107. test_disjoint<ls, ls>("col-op", "LINESTRING(5 5,10 10)", "LINESTRING(6 6,3 3)", false);
  108. test_disjoint<ls, ls>("col-op", "LINESTRING(5 5,2 8)", "LINESTRING(4 6,7 3)", false);
  109. test_disjoint<ls, polygon>("col-op", "LINESTRING(10 10,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  110. test_disjoint<ls, polygon>("col-op", "LINESTRING(9 10,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
  111. // assertion failure in 1.57
  112. test_disjoint<ls, ls>("point_ll_assert_1_57",
  113. "LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)",
  114. "LINESTRING(31 -97, -46 57, -20 -4)",
  115. false);
  116. }
  117. int test_main(int, char* [])
  118. {
  119. test_all<bg::model::d2::point_xy<float> >();
  120. test_all<bg::model::d2::point_xy<double> >();
  121. #ifdef HAVE_TTMATH
  122. test_all<bg::model::d2::point_xy<ttmath_big> >();
  123. #endif
  124. return 0;
  125. }