difference_multi_areal_linear.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  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 <iostream>
  8. #include <string>
  9. //#define HAVE_TTMATH
  10. //#define BOOST_GEOMETRY_DEBUG_ASSEMBLE
  11. //#define BOOST_GEOMETRY_CHECK_WITH_SQLSERVER
  12. //#define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
  13. //#define BOOST_GEOMETRY_DEBUG_FOLLOW
  14. //#define BOOST_GEOMETRY_DEBUG_TRAVERSE
  15. #include "test_difference.hpp"
  16. #include <algorithms/test_overlay.hpp>
  17. #include <algorithms/overlay/multi_overlay_cases.hpp>
  18. #include <boost/geometry/geometries/point_xy.hpp>
  19. #include <boost/geometry/geometries/multi_linestring.hpp>
  20. #include <boost/geometry/geometries/multi_polygon.hpp>
  21. #include <boost/geometry/io/wkt/read.hpp>
  22. template <typename MultiPolygon, typename MultiLineString>
  23. void test_areal_linear()
  24. {
  25. typedef typename boost::range_value<MultiPolygon>::type polygon;
  26. typedef typename boost::range_value<MultiLineString>::type linestring;
  27. typedef typename bg::point_type<polygon>::type point;
  28. typedef bg::model::ring<point> ring;
  29. test_one_lp<linestring, linestring, MultiPolygon>("case_mp_ls_1", "LINESTRING(2 0,2 5)", case_multi_simplex[0], 2, 4, 1.30);
  30. test_one_lp<linestring, MultiLineString, polygon>("case_p_mls_1", "MULTILINESTRING((2 0,2 5),(3 0,3 5))", case_single_simplex, 3, 6, 2.5);
  31. test_one_lp<linestring, MultiLineString, MultiPolygon>("case_mp_mls_1", "MULTILINESTRING((2 0,2 5),(3 0,3 5))", case_multi_simplex[0], 5, 10, 3.1666667);
  32. test_one_lp<linestring, MultiLineString, ring>("case_r_mls_1", "MULTILINESTRING((2 0,2 5),(3 0,3 5))", case_single_simplex, 3, 6, 2.5);
  33. // Collinear cases, with multiple turn points at the same location
  34. test_one_lp<linestring, linestring, MultiPolygon>("case_mp_ls_2a", "LINESTRING(1 0,1 1,2 1,2 0)", "MULTIPOLYGON(((0 0,0 1,1 1,1 0,0 0)),((1 1,1 2,2 2,2 1,1 1)))", 1, 2, 1.0);
  35. test_one_lp<linestring, linestring, MultiPolygon>("case_mp_ls_2b", "LINESTRING(1 0,1 1,2 1,2 0)", "MULTIPOLYGON(((1 1,1 2,2 2,2 1,1 1)),((0 0,0 1,1 1,1 0,0 0)))", 1, 2, 1.0);
  36. test_one_lp<linestring, linestring, MultiPolygon>("case_mp_ls_3",
  37. "LINESTRING(6 6,6 7,7 7,7 6,8 6,8 7,9 7,9 6)",
  38. "MULTIPOLYGON(((5 7,5 8,6 8,6 7,5 7)),((6 6,6 7,7 7,7 6,6 6)),((8 8,9 8,9 7,8 7,7 7,7 8,8 8)))", 2, 5, 3.0);
  39. return;
  40. // TODO: this case contains collinearities and should still be solved
  41. test_one_lp<linestring, linestring, MultiPolygon>("case_mp_ls_4",
  42. "LINESTRING(0 5,0 6,1 6,1 5,2 5,2 6,3 6,3 5,3 4,3 3,2 3,2 4,1 4,1 3,0 3,0 4)",
  43. "MULTIPOLYGON(((0 2,0 3,1 2,0 2)),((2 5,3 6,3 5,2 5)),((1 5,1 6,2 6,2 5,1 5)),((2 3,2 4,3 4,2 3)),((0 3,1 4,1 3,0 3)),((4 3,3 3,3 5,4 5,4 4,4 3)))", 5, 11, 6.0);
  44. }
  45. template <typename P>
  46. void test_all()
  47. {
  48. typedef bg::model::polygon<P> polygon;
  49. typedef bg::model::linestring<P> linestring;
  50. typedef bg::model::multi_polygon<polygon> multi_polygon;
  51. typedef bg::model::multi_linestring<linestring> multi_linestring;
  52. test_areal_linear<multi_polygon, multi_linestring>();
  53. }
  54. int test_main(int, char* [])
  55. {
  56. test_all<bg::model::d2::point_xy<double> >();
  57. #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  58. test_all<bg::model::d2::point_xy<float> >();
  59. #endif
  60. return 0;
  61. }