]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/robustness/overlay/areal_areal/interior_triangles.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / robustness / overlay / areal_areal / interior_triangles.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Robustness Test
3
4 // Copyright (c) 2009-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 <chrono>
15 #include <iostream>
16 #include <sstream>
17 #include <fstream>
18 #include <iomanip>
19 #include <string>
20
21 #include <boost/program_options.hpp>
22 #include <boost/random/linear_congruential.hpp>
23 #include <boost/random/uniform_int.hpp>
24 #include <boost/random/uniform_real.hpp>
25 #include <boost/random/variate_generator.hpp>
26
27 template <typename Polygon>
28 inline void make_polygon(Polygon& polygon, int count_x, int count_y, int index, int offset)
29 {
30 typedef typename bg::point_type<Polygon>::type point_type;
31 bg::exterior_ring(polygon).push_back(point_type(0, 0));
32 bg::exterior_ring(polygon).push_back(point_type(0, count_y * 10));
33 bg::exterior_ring(polygon).push_back(point_type(count_x * 10 + 10, count_y * 10));
34 bg::exterior_ring(polygon).push_back(point_type(count_x * 10 + 10, 0));
35 bg::exterior_ring(polygon).push_back(point_type(0, 0));
36
37 for(int j = 0; j < count_x; ++j)
38 {
39 for(int k = 0; k < count_y; ++k)
40 {
41 polygon.inners().push_back(typename Polygon::inner_container_type::value_type());
42 polygon.inners().back().push_back(point_type(offset + j * 10 + 1, k * 10 + 1));
43 polygon.inners().back().push_back(point_type(offset + j * 10 + 7, k * 10 + 5 + index));
44 polygon.inners().back().push_back(point_type(offset + j * 10 + 5 + index, k * 10 + 7));
45 polygon.inners().back().push_back(point_type(offset + j * 10 + 1, k * 10 + 1));
46 }
47 }
48 bg::correct(polygon);
49 }
50
51
52
53 template <typename Polygon>
54 void test_star_comb(int index, int count_x, int count_y, int offset, p_q_settings const& settings)
55 {
56 Polygon p, q;
57
58 make_polygon(p, count_x, count_y, 0, 0);
59 make_polygon(q, count_x, count_y, 1, offset);
60
61 std::ostringstream out;
62 out << "interior_triangles" << index;
63 test_overlay_p_q
64 <
65 Polygon,
66 typename bg::coordinate_type<Polygon>::type
67 >(out.str(), p, q, settings);
68 }
69
70
71 template <typename T, bool Clockwise, bool Closed>
72 void test_all(int count, int count_x, int count_y, int offset, p_q_settings const& settings)
73 {
74 auto const t0 = std::chrono::high_resolution_clock::now();
75
76 typedef bg::model::polygon
77 <
78 bg::model::d2::point_xy<T>, Clockwise, Closed
79 > polygon;
80
81
82 for(int i = 0; i < count; i++)
83 {
84 test_star_comb<polygon>(i, count_x, count_y, offset, settings);
85 }
86 auto const t = std::chrono::high_resolution_clock::now();
87 auto const elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t - t0).count();
88 std::cout
89 << " type: " << string_from_type<T>::name()
90 << " time: " << elapsed_ms / 1000.0 << std::endl;
91 }
92
93 int main(int argc, char** argv)
94 {
95 BoostGeometryWriteTestConfiguration();
96 try
97 {
98 namespace po = boost::program_options;
99 po::options_description description("=== interior_triangles ===\nAllowed options");
100
101 int offset = 0;
102 int count = 1;
103 int count_x = 10;
104 int count_y = 10;
105 bool ccw = false;
106 bool open = false;
107 p_q_settings settings;
108
109 description.add_options()
110 ("help", "Help message")
111 ("count", po::value<int>(&count)->default_value(1), "Number of tests")
112 ("count_x", po::value<int>(&count_x)->default_value(10), "Triangle count in x-direction")
113 ("count_y", po::value<int>(&count_y)->default_value(10), "Triangle count in y-direction")
114 ("offset", po::value<int>(&offset)->default_value(0), "Offset of second triangle in x-direction")
115 ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
116 ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
117 ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
118 ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
119 ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
120 ;
121
122 po::variables_map varmap;
123 po::store(po::parse_command_line(argc, argv, description), varmap);
124 po::notify(varmap);
125
126 if (varmap.count("help"))
127 {
128 std::cout << description << std::endl;
129 return 1;
130 }
131
132 if (ccw && open)
133 {
134 test_all<default_test_type, false, false>(count, count_x, count_y, offset, settings);
135 }
136 else if (ccw)
137 {
138 test_all<default_test_type, false, true>(count, count_x, count_y, offset, settings);
139 }
140 else if (open)
141 {
142 test_all<default_test_type, true, false>(count, count_x, count_y, offset, settings);
143 }
144 else
145 {
146 test_all<default_test_type, true, true>(count, count_x, count_y, offset, settings);
147 }
148 }
149 catch(std::exception const& e)
150 {
151 std::cout << "Exception " << e.what() << std::endl;
152 }
153 catch(...)
154 {
155 std::cout << "Other exception" << std::endl;
156 }
157
158 return 0;
159 }