1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 //
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 //
5 // This file was modified by Oracle on 2017.
6 // Modifications copyright (c) 2017 Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 //
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 #include <geometry_test_common.hpp>
14
15 #include <boost/foreach.hpp>
16 #include <boost/range/algorithm/copy.hpp>
17 #include <boost/tuple/tuple.hpp>
18 #include <boost/typeof/typeof.hpp>
19
20 #include <algorithms/test_overlay.hpp>
21
22 #include <boost/geometry/geometry.hpp>
23 #include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
24 #include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
25
26 #include <boost/geometry/geometries/point_xy.hpp>
27 #include <boost/geometry/geometries/polygon.hpp>
28
29 #include <boost/geometry/io/wkt/read.hpp>
30
31 #include <boost/assign/list_of.hpp>
32
33
34 template
35 <
36 typename Geometry1,
37 typename Geometry2,
38 bg::overlay_type OverlayType,
39 typename RingIdVector
40 >
test_geometry(std::string const & wkt1,std::string const & wkt2,RingIdVector const & expected_ids)41 void test_geometry(std::string const& wkt1, std::string const& wkt2,
42 RingIdVector const& expected_ids)
43 {
44 typedef bg::detail::overlay::ring_properties
45 <
46 typename bg::point_type<Geometry1>::type,
47 double
48 > properties;
49
50 Geometry1 geometry1;
51 Geometry2 geometry2;
52
53 bg::read_wkt(wkt1, geometry1);
54 bg::read_wkt(wkt2, geometry2);
55
56 typedef std::map<bg::ring_identifier, properties> map_type;
57 map_type selected;
58 std::map<bg::ring_identifier, bg::detail::overlay::ring_turn_info> empty;
59
60 typedef typename bg::strategy::intersection::services::default_strategy
61 <
62 typename bg::cs_tag<Geometry1>::type
63 >::type strategy_type;
64
65 bg::detail::overlay::select_rings<OverlayType>(geometry1, geometry2, empty, selected, strategy_type());
66
67 BOOST_CHECK_EQUAL(selected.size(), expected_ids.size());
68
69 if (selected.size() <= expected_ids.size())
70 {
71 BOOST_AUTO(eit, expected_ids.begin());
72 for(typename map_type::const_iterator it = selected.begin(); it != selected.end(); ++it, ++eit)
73 {
74 bg::ring_identifier const ring_id = it->first;
75 BOOST_CHECK_EQUAL(ring_id.source_index, eit->source_index);
76 BOOST_CHECK_EQUAL(ring_id.multi_index, eit->multi_index);
77 BOOST_CHECK_EQUAL(ring_id.ring_index, eit->ring_index);
78 }
79 }
80 }
81
82
83
84
85 template <typename P>
test_all()86 void test_all()
87 {
88 // Point in correct clockwise ring -> should return true
89 typedef bg::ring_identifier rid;
90
91 test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_union>(
92 winded[0], winded[1],
93 boost::assign::list_of
94 (rid(0,-1,-1))
95 (rid(0,-1, 0))
96 (rid(0,-1, 1))
97 (rid(0,-1, 3))
98 (rid(1,-1, 1))
99 (rid(1,-1, 2)));
100
101 test_geometry<bg::model::polygon<P>, bg::model::polygon<P>, bg::overlay_intersection>(
102 winded[0], winded[1],
103 boost::assign::list_of
104 (rid(0,-1, 2))
105 (rid(1,-1,-1))
106 (rid(1,-1, 0))
107 (rid(1,-1, 3)));
108 }
109
110
111
112
test_main(int,char * [])113 int test_main( int , char* [] )
114 {
115 test_all<bg::model::d2::point_xy<double> >();
116
117 return 0;
118 }
119