/Src/Dependencies/Boost/libs/geometry/test/algorithms/disjoint.cpp

http://hadesmem.googlecode.com/ · C++ · 132 lines · 74 code · 31 blank · 27 comment · 1 complexity · be14838447c1732ac2af7456c3835d71 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <iostream>
  12. #include <string>
  13. #include <geometry_test_common.hpp>
  14. #include <boost/geometry/algorithms/disjoint.hpp>
  15. #include <boost/geometry/geometries/geometries.hpp>
  16. #include <boost/geometry/geometries/point_xy.hpp>
  17. #include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
  18. #include <boost/geometry/strategies/strategies.hpp>
  19. #include <test_common/test_point.hpp>
  20. #include <algorithms/test_relate.hpp>
  21. template <typename G1, typename G2>
  22. void test_disjoint(std::string const& id,
  23. std::string const& wkt1,
  24. std::string const& wkt2, bool expected)
  25. {
  26. G1 g1;
  27. bg::read_wkt(wkt1, g1);
  28. G2 g2;
  29. bg::read_wkt(wkt2, g2);
  30. bool detected = bg::disjoint(g1, g2);
  31. BOOST_CHECK_MESSAGE(detected == expected,
  32. "disjoint: " << id
  33. << " -> Expected: " << expected
  34. << " detected: " << detected);
  35. }
  36. template <typename P>
  37. void test_all()
  38. {
  39. typedef bg::model::box<P> box;
  40. test_disjoint<P, P>("pp1", "point(1 1)", "point(1 1)", false);
  41. test_disjoint<P, P>("pp2", "point(1 1)", "point(1.001 1)", true);
  42. // left-right
  43. test_disjoint<box, box>("bb1", "box(1 1, 2 2)", "box(3 1, 4 2)", true);
  44. test_disjoint<box, box>("bb2", "box(1 1, 2 2)", "box(2 1, 3 2)", false);
  45. test_disjoint<box, box>("bb3", "box(1 1, 2 2)", "box(2 2, 3 3)", false);
  46. test_disjoint<box, box>("bb4", "box(1 1, 2 2)", "box(2.001 2, 3 3)", true);
  47. // up-down
  48. test_disjoint<box, box>("bb5", "box(1 1, 2 2)", "box(1 3, 2 4)", true);
  49. test_disjoint<box, box>("bb6", "box(1 1, 2 2)", "box(1 2, 2 3)", false);
  50. // right-left
  51. test_disjoint<box, box>("bb7", "box(1 1, 2 2)", "box(0 1, 1 2)", false);
  52. test_disjoint<box, box>("bb8", "box(1 1, 2 2)", "box(0 1, 1 2)", false);
  53. // point-box
  54. test_disjoint<P, box>("pb1", "point(1 1)", "box(0 0, 2 2)", false);
  55. test_disjoint<P, box>("pb2", "point(2 2)", "box(0 0, 2 2)", false);
  56. test_disjoint<P, box>("pb3", "point(2.0001 2)", "box(1 1, 2 2)", true);
  57. test_disjoint<P, box>("pb4", "point(0.9999 2)", "box(1 1, 2 2)", true);
  58. // box-point (to test reverse compiling)
  59. test_disjoint<box, P>("bp1", "box(1 1, 2 2)", "point(2 2)", false);
  60. // Test triangles for polygons/rings, boxes
  61. // Note that intersections are tested elsewhere, they don't need
  62. // thorough test at this place
  63. typedef bg::model::polygon<P> polygon;
  64. typedef bg::model::ring<P> ring;
  65. // Four times same test with other types
  66. test_disjoint<polygon, polygon>("disjoint_simplex_pp", disjoint_simplex[0], disjoint_simplex[1], true);
  67. test_disjoint<ring, polygon>("disjoint_simplex_rp", disjoint_simplex[0], disjoint_simplex[1], true);
  68. test_disjoint<ring, ring>("disjoint_simplex_rr", disjoint_simplex[0], disjoint_simplex[1], true);
  69. test_disjoint<polygon, ring>("disjoint_simplex_pr", disjoint_simplex[0], disjoint_simplex[1], true);
  70. // Testing touch
  71. test_disjoint<polygon, polygon>("touch_simplex_pp", touch_simplex[0], touch_simplex[1], false);
  72. // Testing overlap (and test compiling with box)
  73. test_disjoint<polygon, polygon>("overlaps_box_pp", overlaps_box[0], overlaps_box[1], false);
  74. test_disjoint<box, polygon>("overlaps_box_bp", overlaps_box[0], overlaps_box[1], false);
  75. test_disjoint<box, ring>("overlaps_box_br", overlaps_box[0], overlaps_box[1], false);
  76. test_disjoint<polygon, box>("overlaps_box_pb", overlaps_box[1], overlaps_box[0], false);
  77. test_disjoint<ring, box>("overlaps_box_rb", overlaps_box[1], overlaps_box[0], false);
  78. // Test if within(a,b) returns false for disjoint
  79. test_disjoint<ring, ring>("within_simplex_rr1", within_simplex[0], within_simplex[1], false);
  80. test_disjoint<ring, ring>("within_simplex_rr2", within_simplex[1], within_simplex[0], false);
  81. // Linear
  82. typedef bg::model::linestring<P> ls;
  83. typedef bg::model::segment<P> segment;
  84. test_disjoint<ls, ls>("ls/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  85. test_disjoint<ls, ls>("ls/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  86. test_disjoint<segment, segment>("s/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  87. test_disjoint<segment, segment>("s/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  88. // TODO test_disjoint<segment, ls>("s/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  89. // TODO test_disjoint<segment, ls>("s/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  90. // TODO test_disjoint<ls, segment>("ls/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
  91. // TODO test_disjoint<ls, segment>("ls/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
  92. }
  93. int test_main(int, char* [])
  94. {
  95. test_all<bg::model::d2::point_xy<float> >();
  96. test_all<bg::model::d2::point_xy<double> >();
  97. #ifdef HAVE_TTMATH
  98. test_all<bg::model::d2::point_xy<ttmath_big> >();
  99. #endif
  100. return 0;
  101. }