]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/robustness/overlay/areal_areal/intersects.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / robustness / overlay / areal_areal / intersects.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Robustness Test
3
4 // Copyright (c) 2011-2020 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #define BOOST_GEOMETRY_NO_BOOST_TEST
11
12 #include <test_overlay_p_q.hpp>
13
14 #include <iostream>
15 #include <sstream>
16 #include <fstream>
17 #include <iomanip>
18 #include <string>
19
20 #include <boost/program_options.hpp>
21 #include <boost/random/linear_congruential.hpp>
22 #include <boost/random/uniform_int.hpp>
23 #include <boost/random/uniform_real.hpp>
24 #include <boost/random/variate_generator.hpp>
25
26
27 template <typename MultiPolygon>
28 inline void make_polygon(MultiPolygon& mp, int count_x, int count_y, int index, int width_x)
29 {
30 typedef typename bg::point_type<MultiPolygon>::type point_type;
31
32 for(int j = 0; j < count_x; ++j)
33 {
34 for(int k = 0; k < count_y; ++k)
35 {
36 mp.push_back(typename MultiPolygon::value_type());
37 mp.back().outer().push_back(point_type(width_x + j * 10 + 1, k * 10 + 1));
38 mp.back().outer().push_back(point_type(width_x + j * 10 + width_x, k * 10 + 5 + index));
39 mp.back().outer().push_back(point_type(width_x + j * 10 + 5 + index, k * 10 + 7));
40 mp.back().outer().push_back(point_type(width_x + j * 10 + 1, k * 10 + 1));
41 }
42 }
43 }
44
45
46
47 template <typename MultiPolygon>
48 void test_intersects(int count_x, int count_y, int width_x, p_q_settings const& settings)
49 {
50 MultiPolygon mp;
51
52 make_polygon(mp, count_x, count_y, 0, width_x);
53
54 bool const b = bg::intersects(mp);
55 if (b)
56 {
57 std::cout << " YES";
58 }
59
60 if(settings.svg)
61 {
62 typedef typename bg::coordinate_type<MultiPolygon>::type coordinate_type;
63 typedef typename bg::point_type<MultiPolygon>::type point_type;
64 std::ostringstream filename;
65 filename << "intersects_"
66 << string_from_type<coordinate_type>::name()
67 << ".svg";
68
69 std::ofstream svg(filename.str().c_str());
70 bg::svg_mapper<point_type> mapper(svg, 500, 500);
71 mapper.add(mp);
72 mapper.map(mp, "fill-opacity:0.5;fill:rgb(153,204,0);"
73 "stroke:rgb(153,204,0);stroke-width:3");
74 }
75 }
76
77
78 template <typename T, bool Clockwise, bool Closed>
79 void test_all(int count, int count_x, int count_y, int width_x, p_q_settings const& settings)
80 {
81 auto const t0 = std::chrono::high_resolution_clock::now();
82
83 typedef bg::model::polygon
84 <
85 bg::model::d2::point_xy<T>, Clockwise, Closed
86 > polygon;
87 typedef bg::model::multi_polygon
88 <
89 polygon
90 > multi_polygon;
91
92
93 for(int i = 0; i < count; i++)
94 {
95 test_intersects<multi_polygon>(count_x, count_y, width_x, settings);
96 }
97 auto const t = std::chrono::high_resolution_clock::now();
98 auto const elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t - t0).count();
99 std::cout
100 << " type: " << string_from_type<T>::name()
101 << " time: " << elapsed_ms / 1000.0 << std::endl;
102 }
103
104 int main(int argc, char** argv)
105 {
106 BoostGeometryWriteTestConfiguration();
107 try
108 {
109 namespace po = boost::program_options;
110 po::options_description description("=== intersects ===\nAllowed options");
111
112 int width_x = 7;
113 int count = 1;
114 int count_x = 10;
115 int count_y = 10;
116 bool ccw = false;
117 bool open = false;
118 p_q_settings settings;
119
120 description.add_options()
121 ("help", "Help message")
122 ("count", po::value<int>(&count)->default_value(1), "Number of tests")
123 ("count_x", po::value<int>(&count_x)->default_value(10), "Triangle count in x-direction")
124 ("count_y", po::value<int>(&count_y)->default_value(10), "Triangle count in y-direction")
125 ("width_x", po::value<int>(&width_x)->default_value(7), "Width of triangle in x-direction")
126 ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
127 ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
128 ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
129 ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
130 ;
131
132 po::variables_map varmap;
133 po::store(po::parse_command_line(argc, argv, description), varmap);
134 po::notify(varmap);
135
136 if (varmap.count("help"))
137 {
138 std::cout << description << std::endl;
139 return 1;
140 }
141
142 if (ccw && open)
143 {
144 test_all<default_test_type, false, false>(count, count_x, count_y, width_x, settings);
145 }
146 else if (ccw)
147 {
148 test_all<default_test_type, false, true>(count, count_x, count_y, width_x, settings);
149 }
150 else if (open)
151 {
152 test_all<default_test_type, true, false>(count, count_x, count_y, width_x, settings);
153 }
154 else
155 {
156 test_all<default_test_type, true, true>(count, count_x, count_y, width_x, settings);
157 }
158 }
159 catch(std::exception const& e)
160 {
161 std::cout << "Exception " << e.what() << std::endl;
162 }
163 catch(...)
164 {
165 std::cout << "Other exception" << std::endl;
166 }
167
168 return 0;
169 }