Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / geometry / test / algorithms / overlay / select_rings.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 //
3 // Copyright (c) 2007-2012 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
8 #include <geometry_test_common.hpp>
9
10 #include <boost/foreach.hpp>
11 #include <boost/range/algorithm/copy.hpp>
12 #include <boost/tuple/tuple.hpp>
13 #include <boost/typeof/typeof.hpp>
14
15 #include <algorithms/test_overlay.hpp>
16
17 #include <boost/geometry/geometry.hpp>
18 #include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
19 #include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
20
21 #include <boost/geometry/geometries/point_xy.hpp>
22 #include <boost/geometry/geometries/polygon.hpp>
23
24 #include <boost/geometry/io/wkt/read.hpp>
25
26 #include <boost/assign/list_of.hpp>
27
28
29 template
30 <
31     typename Geometry1,
32     typename Geometry2,
33     bg::overlay_type OverlayType,
34     typename RingIdVector
35 >
36 void test_geometry(std::string const& wkt1, std::string const& wkt2,
37     RingIdVector const& expected_ids)
38 {
39     typedef bg::detail::overlay::ring_properties<typename bg::point_type<Geometry1>::type> properties;
40
41     Geometry1 geometry1;
42     Geometry2 geometry2;
43
44     bg::read_wkt(wkt1, geometry1);
45     bg::read_wkt(wkt2, geometry2);
46
47     typedef std::map<bg::ring_identifier, properties> map_type;
48     map_type selected;
49     std::map<bg::ring_identifier, bg::detail::overlay::ring_turn_info> empty;
50
51     bg::detail::overlay::select_rings<OverlayType>(geometry1, geometry2, empty, selected);
52
53     BOOST_CHECK_EQUAL(selected.size(), expected_ids.size());
54
55     if (selected.size() <= expected_ids.size())
56     {
57         BOOST_AUTO(eit, expected_ids.begin());
58         for(typename map_type::const_iterator it = selected.begin(); it != selected.end(); ++it, ++eit)
59         {
60             bg::ring_identifier const ring_id = it->first;
61             BOOST_CHECK_EQUAL(ring_id.source_index, eit->source_index);
62             BOOST_CHECK_EQUAL(ring_id.multi_index, eit->multi_index);
63             BOOST_CHECK_EQUAL(ring_id.ring_index, eit->ring_index);
64         }
65     }
66 }
67
68
69
70
71 template <typename P>
72 void test_all()
73 {
74     // Point in correct clockwise ring -> should return true
75     typedef bg::ring_identifier rid;
76
77     test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_union>(
78         winded[0], winded[1],
79         boost::assign::list_of
80                 (rid(0,-1,-1))
81                 (rid(0,-1, 0))
82                 (rid(0,-1, 1))
83                 (rid(0,-1, 3))
84                 (rid(1,-1, 1))
85                 (rid(1,-1, 2)));
86
87     test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_intersection>(
88             winded[0], winded[1],
89         boost::assign::list_of
90                 (rid(0,-1, 2))
91                 (rid(1,-1,-1))
92                 (rid(1,-1, 0))
93                 (rid(1,-1, 3)));
94 }
95
96
97
98
99 int test_main( int , char* [] )
100 {
101     test_all<bg::model::d2::point_xy<double> >();
102
103     return 0;
104 }