]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/overlay/enrich_intersection_points.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / overlay / enrich_intersection_points.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15 #error This unit test is not updated for several years
16
17 #include <iostream>
18
19 #include <geometry_test_common.hpp>
20
21 #include <boost/geometry/algorithms/intersection.hpp>
22
23 //#include <boost/geometry/algorithms/detail/overlay/get_intersection_points.hpp>
24 //#include <boost/geometry/algorithms/detail/overlay/merge_intersection_points.hpp>
25 #include <boost/geometry/algorithms/detail/overlay/enrich_intersection_points.hpp>
26
27 #include <boost/geometry/strategies/strategies.hpp>
28
29 #define GEOMETRY_TEST_OVERLAY_NOT_REVERSED
30
31
32 #include <boost/algorithm/string/replace.hpp>
33
34
35 #if defined(TEST_WITH_SVG)
36 # include <boost/geometry/io/svg/svg_mapper.hpp>
37 #endif
38
39 struct test_enrich_intersection_points
40 {
41 static inline std::string dir(int d)
42 {
43 return d == 0 ? "-" : (d == 1 ? "L" : "R");
44 }
45
46 template <typename G1, typename G2>
47 static void apply(std::string const& id,
48 boost::tuple<int, std::string> const& expected_count_and_center,
49 G1 const& g1, G2 const& g2, double precision)
50 {
51 //std::cout << "#" << id << std::endl;
52
53 typedef bg::detail::intersection::intersection_point
54 <typename bg::point_type<G2>::type> ip;
55 typedef typename boost::range_const_iterator<std::vector<ip> >::type iterator;
56 std::vector<ip> ips;
57
58 bg::get_intersection_points(g1, g2, ips);
59 bg::merge_intersection_points(ips);
60 bg::enrich_intersection_points(ips, true);
61
62 std::ostringstream out;
63 out << std::setprecision(2);
64
65 bool first = true;
66 for (iterator it = boost::begin(ips); it != boost::end(ips); ++it, first = false)
67 {
68 out << (first ? "" : ",");
69 for (unsigned int i = 0; i < it->info.size(); i++)
70 {
71 out << dir(it->info[i].direction);
72 }
73 }
74 int n = boost::size(ips);
75 //std::cout << n << " " << out.str() << std::endl;
76 BOOST_CHECK_EQUAL(expected_count_and_center.get<0>(), n);
77 BOOST_CHECK_EQUAL(expected_count_and_center.get<1>(), out.str());
78
79
80
81 #if defined(TEST_WITH_SVG)
82 {
83 std::ostringstream filename;
84 filename << "enrich_ip" << id << ".svg";
85
86 std::ofstream svg(filename.str().c_str());
87
88 bg::svg_mapper<typename bg::point_type<G2>::type> mapper(svg, 500, 500);
89 mapper.add(g1);
90 mapper.add(g2);
91
92 mapper.map(g1, "fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");
93 mapper.map(g2, "opacity:0.8;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");
94
95 for (iterator it = boost::begin(ips); it != boost::end(ips); ++it)
96 {
97 mapper.map(it->point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
98 }
99 }
100 #endif
101 }
102 };
103
104
105 int test_main(int, char* [])
106 {
107 std::vector<boost::tuple<int, std::string> > expected;
108
109 /*
110 TODO Will be refactored
111
112 // NOTE: the order is sometimes not really important, in GCC it is sometimes
113 // different from here...
114
115
116 // 1-6
117 expected.push_back(boost::make_tuple(6, "RL,LR,LR,RL,RL,LR"));
118 expected.push_back(boost::make_tuple(8, "RL,LR,LR,RL,RL,LR,LR,RL"));
119 expected.push_back(boost::make_tuple(4, "RLRR,RRRL,RRRL,RRRL"));
120 expected.push_back(boost::make_tuple(12, "RL,LR,RL,LR,LR,RL,RL,LR,LR,RL,LR,RL"));
121 expected.push_back(boost::make_tuple(17, "LR,RL,LR,RRLR,RL,LR,RL,RL,LR,LR,RL,LR,RL,RL,LR,RL,LR"));
122 expected.push_back(boost::make_tuple(2, "--RR,LR"));
123
124 // 7-12
125 expected.push_back(boost::make_tuple(2, "LL,LL"));
126 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
127 expected.push_back(boost::make_tuple(1, "RLLL"));
128 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
129 expected.push_back(boost::make_tuple(1, "RRLR"));
130 expected.push_back(boost::make_tuple(8, "RL,LR,RL,LR,RL,LR,RL,LR"));
131
132 // 13-18
133 expected.push_back(boost::make_tuple(2, "LL--,LL--"));
134 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
135 expected.push_back(boost::make_tuple(2, "RL--,LL--"));
136 expected.push_back(boost::make_tuple(2, "LL,--RL"));
137 expected.push_back(boost::make_tuple(2, "RR--,--LR"));
138 expected.push_back(boost::make_tuple(2, "RR--,--LR"));
139
140 // 19-24
141 expected.push_back(boost::make_tuple(2, "LL,LL"));
142 expected.push_back(boost::make_tuple(0, ""));
143 expected.push_back(boost::make_tuple(0, ""));
144 expected.push_back(boost::make_tuple(1, "RLLLRRLR"));
145 expected.push_back(boost::make_tuple(2, "RL,RLRRRRLR"));
146 expected.push_back(boost::make_tuple(1, "LRRRRRLR"));
147
148 // 25-30
149 expected.push_back(boost::make_tuple(1, "LRRRLLRL"));
150 expected.push_back(boost::make_tuple(1, "LRLLLLLR"));
151 expected.push_back(boost::make_tuple(2, "LR,LRRRRRRL"));
152 expected.push_back(boost::make_tuple(2, "LR,LRLLRRLR"));
153 expected.push_back(boost::make_tuple(2, "RL,LRRRLLLR"));
154 expected.push_back(boost::make_tuple(2, "LR,LRLLLLRL"));
155
156 // 31-36
157 expected.push_back(boost::make_tuple(1, "--LLLL--"));
158 expected.push_back(boost::make_tuple(1, "LR--LLRL"));
159 expected.push_back(boost::make_tuple(1, "LRLLLL--"));
160 expected.push_back(boost::make_tuple(2, "LR,LRLLRR--"));
161 expected.push_back(boost::make_tuple(1, "LRLLRRLR"));
162 expected.push_back(boost::make_tuple(3, "RL,LR,RLLLRRLR"));
163
164 // 37-42
165 expected.push_back(boost::make_tuple(3, "LRRRRRLR,RL,LR"));
166 expected.push_back(boost::make_tuple(3, "LR--RRRL,LR,RL"));
167 expected.push_back(boost::make_tuple(3, "RL,LR,LRRRRRRL"));
168
169 // 43-48
170 expected.push_back(boost::make_tuple(4, "LR,RL,RL,LR"));
171
172 // 49
173 expected.push_back(boost::make_tuple(16, "--RL,RRLR,RRLR,RL,LLRL,RLLLRRLR,RR--,--LR,RLRR,--LL,RL--,RL,RRRL,RL,LR,RRRLRRRL"));
174
175 // 101
176 expected.push_back(boost::make_tuple(3, "RL,LR,RL"));
177
178 // ticket#17
179 expected.push_back(boost::make_tuple(6, "LR,RL,LR,RL,RL,LR"));
180
181 //test_all<bg::model::d2::point_xy<float>, test_enrich_intersection_points>(expected);
182 test_all<bg::model::d2::point_xy<double>, test_enrich_intersection_points>(expected);
183 //test_all<boost::tuple<double, double>, test_enrich_intersection_points>(expected);
184
185 */
186 return 0;
187 }