]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/robustness/overlay/areal_areal/intersection_stars.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2009-2021 Barend Gehrels, Amsterdam, the Netherlands.
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)
10 #define BOOST_GEOMETRY_NO_BOOST_TEST
12 #ifndef BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE
13 #define BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE
16 // NOTE: there is no randomness here. Count is to measure performance
18 #include <test_overlay_p_q.hpp>
25 #include <boost/program_options.hpp>
27 template <typename Polygon
>
28 inline void make_star(Polygon
& polygon
,
29 int count
, double factor1
, double factor2
, long double offset
= 0)
31 typedef typename
bg::point_type
<Polygon
>::type p
;
32 typedef typename
bg::select_most_precise
34 typename
bg::coordinate_type
<Polygon
>::type
,
36 >::type coordinate_type
;
39 coordinate_type cx
= 25.0;
40 coordinate_type cy
= 25.0;
42 coordinate_type dx
= 50.0;
43 coordinate_type dy
= 50.0;
45 coordinate_type half
= 0.5;
46 coordinate_type two
= 2.0;
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
;
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
)
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
));
66 bg::exterior_ring(polygon
).push_back(bg::exterior_ring(polygon
).front());
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
)
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
;
78 for (int c
= 0; c
< count
; c
++)
80 for (int i
= min_points
; i
<= max_points
; i
++)
82 std::ostringstream out
;
83 out
<< "stars_" << c
<< "_" << i
;
86 make_star(p
, i
* 2 + 1, 0.5, 1.0);
88 make_star(q
, i
* 2 + 1, 0.5, 1.0, rotation
);
90 if (! test_overlay_p_q
94 >(out
.str(), p
, q
, settings
))
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();
105 << " type: " << string_from_type
<T
>::name()
106 << " time: " << elapsed_ms
/ 1000.0 << std::endl
;
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
)
112 test_star
<T
, CalculationType
>(count
, min_points
, max_points
, rotation
, settings
);
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
)
118 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
121 settings
.tolerance
= 1.0e-3;
122 test_type
<float, float>(count
, min_points
, max_points
, rotation
, settings
);
124 else if (type
== "double")
127 test_type
<double, double>(count
, min_points
, max_points
, rotation
, settings
);
131 int main(int argc
, char** argv
)
133 BoostGeometryWriteTestConfiguration();
136 namespace po
= boost::program_options
;
137 po::options_description
description("=== recursive_polygons ===\nAllowed options");
140 //int seed = static_cast<unsigned int>(std::time(0));
141 std::string type
= "double";
146 double rotation
= 1.0e-13;
147 p_q_settings settings
;
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)")
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")
166 po::variables_map varmap
;
167 po::store(po::parse_command_line(argc
, argv
, description
), varmap
);
170 if (varmap
.count("help"))
172 std::cout
<< description
<< std::endl
;
176 test_all(type
, count
, min_points
, max_points
, rotation
, settings
);
178 catch(std::exception
const& e
)
180 std::cout
<< "Exception " << e
.what() << std::endl
;
184 std::cout
<< "Other exception" << std::endl
;