]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/robustness/overlay/areal_areal/intersection_stars.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / robustness / overlay / areal_areal / intersection_stars.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Robustness Test
3
4 // Copyright (c) 2009-2021 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 #ifndef BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE
13 #define BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE
14 #endif
15
16 // NOTE: there is no randomness here. Count is to measure performance
17
18 #include <test_overlay_p_q.hpp>
19
20 #include <chrono>
21 #include <iostream>
22 #include <string>
23 #include <sstream>
24
25 #include <boost/program_options.hpp>
26
27 template <typename Polygon>
28 inline void make_star(Polygon& polygon,
29 int count, double factor1, double factor2, long double offset = 0)
30 {
31 typedef typename bg::point_type<Polygon>::type p;
32 typedef typename bg::select_most_precise
33 <
34 typename bg::coordinate_type<Polygon>::type,
35 long double
36 >::type coordinate_type;
37
38 // Create star
39 coordinate_type cx = 25.0;
40 coordinate_type cy = 25.0;
41
42 coordinate_type dx = 50.0;
43 coordinate_type dy = 50.0;
44
45 coordinate_type half = 0.5;
46 coordinate_type two = 2.0;
47
48 coordinate_type a1 = coordinate_type(factor1) * half * dx;
49 coordinate_type b1 = coordinate_type(factor1) * half * dy;
50 coordinate_type a2 = coordinate_type(factor2) * half * dx;
51 coordinate_type b2 = coordinate_type(factor2) * half * dy;
52
53 coordinate_type pi = boost::math::constants::pi<long double>();
54 coordinate_type delta = pi * two / coordinate_type(count - 1);
55 coordinate_type angle = coordinate_type(offset) * delta;
56 for (int i = 0; i < count - 1; i++, angle += delta)
57 {
58 bool even = i % 2 == 0;
59 coordinate_type s = sin(angle);
60 coordinate_type c = cos(angle);
61 coordinate_type x = cx + (even ? a1 : a2) * s;
62 coordinate_type y = cy + (even ? b1 : b2) * c;
63 bg::exterior_ring(polygon).push_back(bg::make<p>(x, y));
64
65 }
66 bg::exterior_ring(polygon).push_back(bg::exterior_ring(polygon).front());
67 }
68
69
70 template <typename T, typename CalculationType>
71 void test_star(int count, int min_points, int max_points, T rotation, p_q_settings const& settings)
72 {
73 auto const t0 = std::chrono::high_resolution_clock::now();
74 typedef bg::model::d2::point_xy<T> point_type;
75 typedef bg::model::polygon<point_type> polygon;
76
77 int n = 0;
78 for (int c = 0; c < count; c++)
79 {
80 for (int i = min_points; i <= max_points; i++)
81 {
82 std::ostringstream out;
83 out << "stars_" << c << "_" << i;
84
85 polygon p;
86 make_star(p, i * 2 + 1, 0.5, 1.0);
87 polygon q;
88 make_star(q, i * 2 + 1, 0.5, 1.0, rotation);
89
90 if (! test_overlay_p_q
91 <
92 polygon,
93 CalculationType
94 >(out.str(), p, q, settings))
95 {
96 return;
97 }
98 n++;
99 }
100 }
101 auto const t = std::chrono::high_resolution_clock::now();
102 auto const elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t - t0).count();
103 std::cout
104 << "polygons: " << n
105 << " type: " << string_from_type<T>::name()
106 << " time: " << elapsed_ms / 1000.0 << std::endl;
107 }
108
109 template <typename T, typename CalculationType>
110 void test_type(int count, int min_points, int max_points, T rotation, p_q_settings const& settings)
111 {
112 test_star<T, CalculationType>(count, min_points, max_points, rotation, settings);
113 }
114
115 template <typename T>
116 void test_all(std::string const& type, int count, int min_points, int max_points, T rotation, p_q_settings settings)
117 {
118 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
119 if (type == "float")
120 {
121 settings.tolerance = 1.0e-3;
122 test_type<float, float>(count, min_points, max_points, rotation, settings);
123 }
124 else if (type == "double")
125 #endif
126 {
127 test_type<double, double>(count, min_points, max_points, rotation, settings);
128 }
129 }
130
131 int main(int argc, char** argv)
132 {
133 BoostGeometryWriteTestConfiguration();
134 try
135 {
136 namespace po = boost::program_options;
137 po::options_description description("=== recursive_polygons ===\nAllowed options");
138
139 int count = 1;
140 //int seed = static_cast<unsigned int>(std::time(0));
141 std::string type = "double";
142 int min_points = 9;
143 int max_points = 9;
144 bool ccw = false;
145 bool open = false;
146 double rotation = 1.0e-13;
147 p_q_settings settings;
148
149 description.add_options()
150 ("help", "Help message")
151 // ("seed", po::value<int>(&seed), "Initialization seed for random generator")
152 ("count", po::value<int>(&count)->default_value(1), "Number of tests")
153 ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
154 ("min_points", po::value<int>(&min_points)->default_value(9), "Minimum number of points")
155 ("max_points", po::value<int>(&max_points)->default_value(9), "Maximum number of points")
156 ("rotation", po::value<double>(&rotation)->default_value(1.0e-13), "Rotation angle")
157 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
158 ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
159 ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
160 ("type", po::value<std::string>(&type)->default_value("double"), "Type (float,double)")
161 #endif
162 ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
163 ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
164 ;
165
166 po::variables_map varmap;
167 po::store(po::parse_command_line(argc, argv, description), varmap);
168 po::notify(varmap);
169
170 if (varmap.count("help"))
171 {
172 std::cout << description << std::endl;
173 return 1;
174 }
175
176 test_all(type, count, min_points, max_points, rotation, settings);
177 }
178 catch(std::exception const& e)
179 {
180 std::cout << "Exception " << e.what() << std::endl;
181 }
182 catch(...)
183 {
184 std::cout << "Other exception" << std::endl;
185 }
186 return 0;
187 }