touches_multi.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2010-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_touches.hpp"
  8. #include <boost/geometry/algorithms/area.hpp>
  9. #include <boost/geometry/algorithms/num_geometries.hpp>
  10. #include <boost/geometry/algorithms/within.hpp>
  11. template <typename P>
  12. void test_all()
  13. {
  14. typedef bg::model::polygon<P> polygon;
  15. typedef bg::model::multi_polygon<polygon> mp;
  16. typedef bg::model::linestring<P> linestring;
  17. typedef bg::model::multi_linestring<linestring> ml;
  18. test_self_touches<mp>("MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))",
  19. false);
  20. // Exactly equal
  21. test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))",
  22. "MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))",
  23. false);
  24. // Spatially equal
  25. test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))",
  26. "MULTIPOLYGON(((0 0,0 100,100 100,100 80,100 20,100 0,0 0)))",
  27. false);
  28. // One exactly equal, another pair touching
  29. test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  30. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((30 10,30 20,40 20,40 10,30 10)))",
  31. false);
  32. // One spatially equal (without equal segments), another pair touching
  33. test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 5,0 10,5 10,10 10,10 5,10 0,5 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  34. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((30 10,30 20,40 20,40 10,30 10)))",
  35. false);
  36. // Alternate touches
  37. test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  38. "MULTIPOLYGON(((10 10,10 20,20 20,20 10,10 10)),((30 10,30 20,40 20,40 10,30 10)))",
  39. true);
  40. // Touch plus inside
  41. test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  42. "MULTIPOLYGON(((10 10,10 20,20 20,20 10,10 10)),((22 2,28 2,28 8,22 8,22 2)))",
  43. false);
  44. test_touches<mp, ml>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  45. "MULTILINESTRING((10 10,10 20,20 20,20 10,10 10),(30 10,30 20,40 20,40 10,30 10))",
  46. true);
  47. test_touches<mp, ml>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  48. "MULTILINESTRING((10 10,10 20,20 20,20 10,10 10),(22 2,28 2,28 8,22 8,22 2))",
  49. false);
  50. test_touches<mp, ml>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))",
  51. "MULTILINESTRING((10 10,10 20,20 20,20 10,10 10),(50 2,60 2,60 8,50 8,50 2))",
  52. true);
  53. }
  54. int test_main( int , char* [] )
  55. {
  56. test_all<bg::model::d2::point_xy<double> >();
  57. #ifdef HAVE_TTMATH
  58. test_all<bg::model::d2::point_xy<ttmath_big> >();
  59. #endif
  60. return 0;
  61. }