1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2009-2012 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 #include <iostream>
11 #include <sstream>
12 #include <fstream>
13 #include <iomanip>
14 #include <string>
15
16 #define BOOST_GEOMETRY_NO_BOOST_TEST
17
18 #include <test_overlay_p_q.hpp>
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 #include <boost/timer.hpp>
26
27 template <typename Polygon>
make_polygon(Polygon & polygon,int count_x,int count_y,int index,int offset)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>
test_star_comb(int count_x,int count_y,int offset,p_q_settings const & settings)54 void test_star_comb(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";
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>
test_all(int count,int count_x,int count_y,int offset,p_q_settings const & settings)72 void test_all(int count, int count_x, int count_y, int offset, p_q_settings const& settings)
73 {
74 boost::timer t;
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>(count_x, count_y, offset, settings);
85 }
86 std::cout
87 << " type: " << string_from_type<T>::name()
88 << " time: " << t.elapsed() << std::endl;
89 }
90
main(int argc,char ** argv)91 int main(int argc, char** argv)
92 {
93 BoostGeometryWriteTestConfiguration();
94 try
95 {
96 namespace po = boost::program_options;
97 po::options_description description("=== interior_triangles ===\nAllowed options");
98
99 int offset = 0;
100 int count = 1;
101 int count_x = 10;
102 int count_y = 10;
103 bool ccw = false;
104 bool open = false;
105 p_q_settings settings;
106
107 description.add_options()
108 ("help", "Help message")
109 ("count", po::value<int>(&count)->default_value(1), "Number of tests")
110 ("count_x", po::value<int>(&count_x)->default_value(10), "Triangle count in x-direction")
111 ("count_y", po::value<int>(&count_y)->default_value(10), "Triangle count in y-direction")
112 ("offset", po::value<int>(&offset)->default_value(0), "Offset of second triangle in x-direction")
113 ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
114 ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
115 ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
116 ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
117 ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
118 ;
119
120 po::variables_map varmap;
121 po::store(po::parse_command_line(argc, argv, description), varmap);
122 po::notify(varmap);
123
124 if (varmap.count("help"))
125 {
126 std::cout << description << std::endl;
127 return 1;
128 }
129
130 if (ccw && open)
131 {
132 test_all<double, false, false>(count, count_x, count_y, offset, settings);
133 }
134 else if (ccw)
135 {
136 test_all<double, false, true>(count, count_x, count_y, offset, settings);
137 }
138 else if (open)
139 {
140 test_all<double, true, false>(count, count_x, count_y, offset, settings);
141 }
142 else
143 {
144 test_all<double, true, true>(count, count_x, count_y, offset, settings);
145 }
146
147 #if defined(HAVE_TTMATH)
148 // test_all<ttmath_big, true, true>(seed, count, max, svg, level);
149 #endif
150 }
151 catch(std::exception const& e)
152 {
153 std::cout << "Exception " << e.what() << std::endl;
154 }
155 catch(...)
156 {
157 std::cout << "Other exception" << std::endl;
158 }
159
160 return 0;
161 }
162