1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2009-2012 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)
13 #define BOOST_GEOMETRY_NO_BOOST_TEST
16 #include <test_overlay_p_q.hpp>
18 #include <boost/program_options.hpp>
19 #include <boost/timer.hpp>
21 template <typename Polygon>
22 inline void make_star(Polygon& polygon,
23 int count, double factor1, double factor2, long double offset = 0)
25 typedef typename bg::point_type<Polygon>::type p;
26 typedef typename bg::select_most_precise
28 typename bg::coordinate_type<Polygon>::type,
30 >::type coordinate_type;
33 coordinate_type cx = 25.0;
34 coordinate_type cy = 25.0;
36 coordinate_type dx = 50.0;
37 coordinate_type dy = 50.0;
39 coordinate_type half = 0.5;
40 coordinate_type two = 2.0;
42 coordinate_type a1 = coordinate_type(factor1) * half * dx;
43 coordinate_type b1 = coordinate_type(factor1) * half * dy;
44 coordinate_type a2 = coordinate_type(factor2) * half * dx;
45 coordinate_type b2 = coordinate_type(factor2) * half * dy;
47 coordinate_type pi = boost::math::constants::pi<long double>();
48 coordinate_type delta = pi * two / coordinate_type(count - 1);
49 coordinate_type angle = coordinate_type(offset) * delta;
50 for (int i = 0; i < count - 1; i++, angle += delta)
52 bool even = i % 2 == 0;
53 coordinate_type s = sin(angle);
54 coordinate_type c = cos(angle);
55 coordinate_type x = cx + (even ? a1 : a2) * s;
56 coordinate_type y = cy + (even ? b1 : b2) * c;
57 bg::exterior_ring(polygon).push_back(bg::make<p>(x, y));
60 bg::exterior_ring(polygon).push_back(bg::exterior_ring(polygon).front());
64 template <typename T, typename CalculationType>
65 void test_star(int count, int min_points, int max_points, T rotation, p_q_settings const& settings)
68 typedef bg::model::d2::point_xy<T> point_type;
69 typedef bg::model::polygon<point_type> polygon;
72 for (int c = 0; c < count; c++)
74 for (int i = min_points; i <= max_points; i++)
76 std::ostringstream out;
77 out << "_" << string_from_type<T>::name() << "_"
78 << string_from_type<CalculationType>::name() << "_"
82 make_star(p, i * 2 + 1, 0.5, 1.0);
84 make_star(q, i * 2 + 1, 0.5, 1.0, rotation);
86 if (! test_overlay_p_q
90 >(out.str(), p, q, settings))
99 << " type: " << string_from_type<T>::name()
100 << " time: " << t.elapsed() << std::endl;
103 template <typename T, typename CalculationType>
104 void test_type(int count, int min_points, int max_points, T rotation, p_q_settings const& settings)
106 test_star<T, CalculationType>(count, min_points, max_points, rotation, settings);
109 template <typename T>
110 void test_all(std::string const& type, int count, int min_points, int max_points, T rotation, p_q_settings settings)
114 settings.tolerance = 1.0e-3;
115 test_type<float, float>(count, min_points, max_points, rotation, settings);
117 else if (type == "double")
119 test_type<double, double>(count, min_points, max_points, rotation, settings);
121 #if defined(HAVE_TTMATH)
122 else if (type == "ttmath")
124 test_type<ttmath_big, ttmath_big>(count, min_points, max_points, rotation, settings);
129 int main(int argc, char** argv)
133 namespace po = boost::program_options;
134 po::options_description description("=== recursive_polygons ===\nAllowed options");
137 //int seed = static_cast<unsigned int>(std::time(0));
138 std::string type = "float";
143 double rotation = 1.0e-13;
144 p_q_settings settings;
146 description.add_options()
147 ("help", "Help message")
148 //("seed", po::value<int>(&seed), "Initialization seed for random generator")
149 ("count", po::value<int>(&count)->default_value(1), "Number of tests")
150 ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
151 ("min_points", po::value<int>(&min_points)->default_value(9), "Minimum number of points")
152 ("max_points", po::value<int>(&max_points)->default_value(9), "Maximum number of points")
153 ("rotation", po::value<double>(&rotation)->default_value(1.0e-13), "Rotation angle")
154 ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
155 ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
156 ("type", po::value<std::string>(&type)->default_value("float"), "Type (float,double)")
157 ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
158 ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
161 po::variables_map varmap;
162 po::store(po::parse_command_line(argc, argv, description), varmap);
165 if (varmap.count("help"))
167 std::cout << description << std::endl;
171 test_all(type, count, min_points, max_points, rotation, settings);
173 catch(std::exception const& e)
175 std::cout << "Exception " << e.what() << std::endl;
179 std::cout << "Other exception" << std::endl;