]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/robustness/overlay/areal_areal/intersects.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2011-2020 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 #include <test_overlay_p_q.hpp>
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>
27 template <typename MultiPolygon
>
28 inline void make_polygon(MultiPolygon
& mp
, int count_x
, int count_y
, int index
, int width_x
)
30 typedef typename
bg::point_type
<MultiPolygon
>::type point_type
;
32 for(int j
= 0; j
< count_x
; ++j
)
34 for(int k
= 0; k
< count_y
; ++k
)
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));
47 template <typename MultiPolygon
>
48 void test_intersects(int count_x
, int count_y
, int width_x
, p_q_settings
const& settings
)
52 make_polygon(mp
, count_x
, count_y
, 0, width_x
);
54 bool const b
= bg::intersects(mp
);
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()
69 std::ofstream
svg(filename
.str().c_str());
70 bg::svg_mapper
<point_type
> mapper(svg
, 500, 500);
72 mapper
.map(mp
, "fill-opacity:0.5;fill:rgb(153,204,0);"
73 "stroke:rgb(153,204,0);stroke-width:3");
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
)
81 auto const t0
= std::chrono::high_resolution_clock::now();
83 typedef bg::model::polygon
85 bg::model::d2::point_xy
<T
>, Clockwise
, Closed
87 typedef bg::model::multi_polygon
93 for(int i
= 0; i
< count
; i
++)
95 test_intersects
<multi_polygon
>(count_x
, count_y
, width_x
, settings
);
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();
100 << " type: " << string_from_type
<T
>::name()
101 << " time: " << elapsed_ms
/ 1000.0 << std::endl
;
104 int main(int argc
, char** argv
)
106 BoostGeometryWriteTestConfiguration();
109 namespace po
= boost::program_options
;
110 po::options_description
description("=== intersects ===\nAllowed options");
118 p_q_settings settings
;
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")
132 po::variables_map varmap
;
133 po::store(po::parse_command_line(argc
, argv
, description
), varmap
);
136 if (varmap
.count("help"))
138 std::cout
<< description
<< std::endl
;
144 test_all
<default_test_type
, false, false>(count
, count_x
, count_y
, width_x
, settings
);
148 test_all
<default_test_type
, false, true>(count
, count_x
, count_y
, width_x
, settings
);
152 test_all
<default_test_type
, true, false>(count
, count_x
, count_y
, width_x
, settings
);
156 test_all
<default_test_type
, true, true>(count
, count_x
, count_y
, width_x
, settings
);
159 catch(std::exception
const& e
)
161 std::cout
<< "Exception " << e
.what() << std::endl
;
165 std::cout
<< "Other exception" << std::endl
;