]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/overlay/traverse_gmp.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / overlay / traverse_gmp.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
18 #if defined(_MSC_VER)
19 #pragma warning( disable : 4244 )
20 #pragma warning( disable : 4267 )
21 #endif
22
23 //#define GEOMETRY_DEBUG_INTERSECTION
24
25
26 #include <iostream>
27 #include <iomanip>
28 #include <string>
29 #include <fstream>
30
31 #include <boost/numeric_adaptor/numeric_adaptor.hpp>
32 #include <boost/numeric_adaptor/gmp_value_type.hpp>
33
34 #include <boost/geometry/geometry.hpp>
35 #include <boost/geometry/geometries/geometries.hpp>
36 #include <boost/geometry/geometries/point_xy.hpp>
37
38 #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
39 #include <boost/geometry/algorithms/detail/overlay/enrichment_info.hpp>
40 #include <boost/geometry/algorithms/detail/overlay/traversal_info.hpp>
41 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
42 #include <boost/geometry/algorithms/detail/overlay/enrich_intersection_points.hpp>
43 #include <boost/geometry/algorithms/detail/overlay/traverse.hpp>
44
45
46
47 #include <boost/geometry/io/wkt/wkt.hpp>
48
49 #if defined(TEST_WITH_SVG)
50 # include <boost/geometry/io/svg/svg_mapper.hpp>
51 #endif
52
53
54
55 template <typename OutputType, typename G1, typename G2>
56 void test_traverse(std::string const& caseid, G1 const& g1, G2 const& g2)
57 {
58 typedef bg::detail::intersection::intersection_point
59 <typename bg::point_type<G2>::type> ip;
60 typedef typename boost::range_const_iterator<std::vector<ip> >::type iterator;
61 typedef std::vector<ip> ip_vector;
62 ip_vector ips;
63
64 typedef typename bg::strategy::side::services::default_strategy
65 <
66 typename bg::cs_tag<G1>::type
67 >::type strategy_type;
68
69
70 typedef bg::detail::overlay::traversal_turn_info
71 <
72 typename bg::point_type<G2>::type
73 > turn_info;
74 typedef typename boost::range_iterator<const std::vector<turn_info> >::type iterator;
75 std::vector<turn_info> ips;
76
77 bg::get_turns<false, false, bg::detail::overlay::assign_null_policy>(g1, g2, ips);
78 bg::enrich_intersection_points(ips, g1, g2, strategy_type());
79
80 typedef bg::model::ring<typename bg::point_type<G2>::type> ring_type;
81 typedef std::vector<ring_type> out_vector;
82 out_vector v;
83
84
85
86 bg::traverse
87 <
88 strategy_type,
89 ring_type
90 >
91 (
92 g1, g2, -1, ips, std::back_inserter(v)
93 );
94
95
96
97 #if defined(TEST_WITH_SVG)
98 {
99 std::ostringstream filename;
100 filename << "intersection_" << caseid << ".svg";
101
102 std::ofstream svg(filename.str().c_str());
103
104 // Trick to have this always LongDouble
105 //typedef bg::model::d2::point_xy<long double> P;
106 typedef typename bg::point_type<G1>::type P;
107 //typename bg::replace_point_type<G1, P>::type rg1;
108 //typename bg::replace_point_type<G2, P>::type rg2;
109
110 bg::svg_mapper<P> mapper(svg, 1000, 800);
111
112 mapper.add(g1);
113 mapper.add(g2);
114
115 // Input shapes in green/blue
116 mapper.map(g1, "opacity:0.8;fill:rgb(0,255,0);"
117 "stroke:rgb(0,0,0);stroke-width:1");
118 mapper.map(g2, "opacity:0.8;fill:rgb(0,0,255);"
119 "stroke:rgb(0,0,0);stroke-width:1");
120
121 // Traversal rings in red
122 for (typename out_vector::const_iterator it = boost::begin(v);
123 it != boost::end(v);
124 ++it)
125 {
126 mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.9;"
127 "fill:rgb(255,0,0);stroke:rgb(255,0,0);stroke-width:5");
128
129 std::cout << bg::wkt(*it) << std::endl;
130 std::cout << bg::area(*it) << std::endl;
131 }
132
133 // IP's in orange
134 for (iterator it = boost::begin(ips); it != boost::end(ips); ++it)
135 {
136 mapper.map(it->point, "fill:rgb(255,128,0);"
137 "stroke:rgb(0,0,100);stroke-width:1");
138 }
139 }
140 #endif
141 }
142
143 template <typename OutputType, typename G1, typename G2>
144 void test_one(std::string const& caseid, std::string const& wkt1, std::string const& wkt2)
145 {
146 G1 g1;
147 bg::read_wkt(wkt1, g1);
148
149 G2 g2;
150 bg::read_wkt(wkt2, g2);
151
152 bg::correct(g1);
153 bg::correct(g2);
154 std::cout << "area1 " << bg::area(g1) << " " << " area2: " << bg::area(g2) << std::endl;
155
156 test_traverse<OutputType>(caseid, g1, g2);
157 }
158
159
160 #if ! defined(GEOMETRY_TEST_MULTI)
161
162 template <typename P>
163 void test_traverse_gmp(std::string const& caseid)
164 {
165 typedef bg::model::polygon<P> polygon;
166 std::cout << typeid(typename bg::coordinate_type<P>::type).name() << std::endl;
167 std::cout << std::setprecision(30) << std::numeric_limits<float>::epsilon() << std::endl;
168 std::cout << std::setprecision(30) << std::numeric_limits<double>::epsilon() << std::endl;
169 std::cout << std::setprecision(30) << std::numeric_limits<long double>::epsilon() << std::endl;
170
171 static std::string brandon[3] =
172 {
173 //37.43402099609375 1.470055103302002,
174 "POLYGON((37.29449462890625 1.7902572154998779,37.000419616699219 1.664225697517395,37.140213012695313 1.3446992635726929,50.974888957147442 -30.277285722290763,57.297810222148939 -37.546793343968417,41.590042114257813 -7.2021245956420898,40.6978759765625 -5.4500408172607422,40.758884429931641 -5.418975830078125,42.577911376953125 -4.4901103973388672,42.577877044677734 -4.4900407791137695,42.699958801269531 -4.4278755187988281,46.523914387974358 -8.5152102535033496,47.585065917176543 -6.1314922196594779,45.389434814453125 -4.5143837928771973,46.296027072709599 -2.4984308554828116,37.29449462890625 1.7902572154998779))",
175 "POLYGON((42.399410247802734 1.4956772327423096,42.721500396728516 2.2342472076416016,42.721500396728516 3.6584999561309814,51.20102152843122 7.1738039562841562,51.370888500897557 7.4163459734570729,37.43402099609375 1.470055103302002,37.29449462890625 1.7902572154998779,37.000419616699219 1.664225697517395,37.140213012695313 1.3446992635726929,36.954700469970703 1.2597870826721191,26.472516656201325 -3.5380830513658776,27.069889344709196 -4.2926591211028242,30.501169204711914 -2.3718316555023193,32.708126068115234 -2.3611266613006592,32.708126068115234 -2.3611700534820557,32.708168029785156 -2.3611698150634766,32.718830108642578 -4.3281683921813965,29.135100397190627 -8.9262827849488211,29.619997024536133 -9.5368013381958008,30.339155197143555 -8.9838371276855469,30.670633316040039 -8.8180980682373047,30.896280288696289 -9.1206979751586914,30.207040612748258 -10.275926149505661,30.947774887084961 -11.208560943603516,31.669155120849609 -10.653837203979492,32.000633239746094 -10.488097190856934,32.226280212402344 -10.790698051452637,31.682494778186321 -12.133624901803865,32.274600982666016 -12.879127502441406,32.998821258544922 -12.323249816894531,33.339523315429688 -12.147735595703125,33.566280364990234 -12.450697898864746,33.164891643669634 -14.000060288415174,33.598796844482422 -14.546377182006836,34.328716278076172 -13.992490768432617,34.658355712890625 -13.81736946105957,34.886280059814453 -14.120697975158691,34.634240447128811 -15.85007183479255,34.931102752685547 -16.223842620849609,35.656356811523438 -15.66030216217041,35.963497161865234 -15.476018905639648,37.326129913330078 -17.190576553344727,38.823680877685547 -16.296066284179688,39.966808319091797 -17.625011444091797,40.800632476806641 -17.208097457885742,41.821544647216797 -19.211688995361328,41.988733475572282 -19.945838749437218,57.524304765518266 -37.807195733984784,41.590042114257813 -7.2021245956420898,40.6978759765625 -5.4500408172607422,40.758884429931641 -5.418975830078125,42.577911376953125 -4.4901103973388672,42.577877044677734 -4.4900407791137695,42.699958801269531 -4.4278755187988281,46.559533858616469 -8.435196445683264,47.604561877161387 -6.087697464505224,45.389434814453125 -4.5143837928771973,46.695858001708984 -1.6093428134918213,47.263670054709685 -1.784876824891044,47.830955505371094 -0.69758313894271851,48.43512638981781 -0.81299959072453376,49.071769542946825 0.61489892713413252,43.764598846435547 0.93951499462127686,43.644271850585938 0.96149998903274536,42.399410247802734 1.4956772327423096))",
176 "POLYGON((43.644271850585938 0.96149998903274536,43.764598846435547 0.93951499462127686,49.071769542946825 0.61489892713413252,48.43512638981781 -0.81299959072453376,47.830955505371094 -0.69758313894271851,47.263670054709685 -1.784876824891044,46.695858001708984 -1.6093428134918213,45.389434814453125 -4.5143837928771973,47.604561877161387 -6.087697464505224,46.559533858616469 -8.435196445683264,42.699958801269531 -4.4278755187988281,42.577877044677734 -4.4900407791137695,42.577911376953125 -4.4901103973388672,40.758884429931641 -5.418975830078125,40.6978759765625 -5.4500408172607422,41.590042114257813 -7.2021245956420898,57.524304765518266 -37.807195733984784,41.988733475572282 -19.945838749437218,41.821544647216797 -19.211688995361328,40.800632476806641 -17.208097457885742,39.966808319091797 -17.625011444091797,38.823680877685547 -16.296066284179688,37.326129913330078 -17.190576553344727,35.963497161865234 -15.476018905639648,35.656356811523438 -15.66030216217041,34.931102752685547 -16.223842620849609,34.634240447128811 -15.85007183479255,34.886280059814453 -14.120697975158691,34.658355712890625 -13.81736946105957,34.328716278076172 -13.992490768432617,33.598796844482422 -14.546377182006836,33.164891643669634 -14.000060288415174,33.566280364990234 -12.450697898864746,33.339523315429688 -12.147735595703125,32.998821258544922 -12.323249816894531,32.274600982666016 -12.879127502441406,31.682494778186321 -12.133624901803865,32.226280212402344 -10.790698051452637,32.000633239746094 -10.488097190856934,31.669155120849609 -10.653837203979492,30.947774887084961 -11.208560943603516,30.207040612748258 -10.275926149505661,30.896280288696289 -9.1206979751586914,30.670633316040039 -8.8180980682373047,30.339155197143555 -8.9838371276855469,29.619997024536133 -9.5368013381958008,29.135100397190627 -8.9262827849488211,32.718830108642578 -4.3281683921813965,32.708168029785156 -2.3611698150634766,32.708126068115234 -2.3611700534820557,32.708126068115234 -2.3611266613006592,30.501169204711914 -2.3718316555023193,27.069889344709196 -4.2926591211028242,26.472516656201325 -3.5380830513658776,36.954700469970703 1.2597870826721191,37.140213012695313 1.3446992635726929,37.000419616699219 1.664225697517395,37.29449462890625 1.7902572154998779,37.43402099609375 1.470055103302002,51.370888500897557 7.4163459734570729,51.20102152843122 7.1738039562841562,42.721500396728516 3.6584999561309814,42.721500396728516 2.2342472076416016,42.399410247802734 1.4956772327423096,43.644271850585938 0.96149998903274536))"
177 };
178
179
180 // Test the FORWARD case
181 test_one<polygon, polygon, polygon>(caseid, brandon[0], brandon[1]);
182 }
183 #endif
184
185
186
187 int main(int argc, char** argv)
188 {
189 int mode = (argc > 1) ? atol(argv[1]) : 1;
190 switch(mode)
191 {
192 case 1 :
193 test_traverse_gmp<bg::model::d2::point_xy<float> >("float");
194 break;
195 case 2 :
196 test_traverse_gmp<bg::model::d2::point_xy<double> >("double");
197 break;
198 case 3 :
199 test_traverse_gmp<bg::model::d2::point_xy<long double> >("long double");
200 break;
201 case 4 :
202 #if defined(HAVE_TTMATH)
203 test_traverse_gmp<bg::model::d2::point_xy<ttmath_big> >("ttmath_big");
204 #endif
205 break;
206 }
207 return 0;
208 }