• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define BOOST_GEOMETRY_NO_BOOST_TEST
11 
12 #include <test_overlay_p_q.hpp>
13 
14 #include <boost/program_options.hpp>
15 #include <boost/random/linear_congruential.hpp>
16 #include <boost/random/uniform_int.hpp>
17 #include <boost/random/uniform_real.hpp>
18 #include <boost/random/variate_generator.hpp>
19 #include <boost/timer.hpp>
20 
21 #include <star_comb.hpp>
22 
23 
24 template <typename Polygon>
add(Polygon & polygon,double x,double y,int)25 void add(Polygon& polygon, double x, double y, int)
26 {
27     typedef typename boost::geometry::point_type<Polygon>::type p;
28     boost::geometry::exterior_ring(polygon).push_back(boost::geometry::make<p>(x, y));
29 }
30 
31 
32 template <typename Polygon>
test_star_comb(int star_point_count,int comb_comb_count,double factor1,double factor2,bool do_union,p_q_settings const & settings)33 void test_star_comb(int star_point_count, int comb_comb_count, double factor1, double factor2, bool do_union, p_q_settings const& settings)
34 {
35     Polygon star, comb;
36     make_star(star, add<Polygon>, star_point_count, factor1, factor2);
37     make_comb(comb, add<Polygon>, comb_comb_count);
38 
39     std::ostringstream out;
40     out << "star_comb";
41     test_overlay_p_q
42         <
43             Polygon,
44             typename bg::coordinate_type<Polygon>::type
45         >(out.str(), star, comb, settings);
46 }
47 
48 
49 template <typename T, bool Clockwise, bool Closed>
test_all(int count,int star_point_count,int comb_comb_count,double factor1,double factor2,bool do_union,p_q_settings const & settings)50 void test_all(int count, int star_point_count, int comb_comb_count, double factor1, double factor2, bool do_union, p_q_settings const& settings)
51 {
52     boost::timer t;
53 
54     typedef bg::model::polygon
55         <
56             bg::model::d2::point_xy<T>, Clockwise, Closed
57         > polygon;
58 
59     for(int i = 0; i < count; i++)
60     {
61         test_star_comb<polygon>(star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
62     }
63     std::cout
64         << " type: " << string_from_type<T>::name()
65         << " time: " << t.elapsed()  << std::endl;
66 }
67 
main(int argc,char ** argv)68 int main(int argc, char** argv)
69 {
70     BoostGeometryWriteTestConfiguration();
71     try
72     {
73         namespace po = boost::program_options;
74         po::options_description description("=== star_comb ===\nAllowed options");
75 
76         int count = 1;
77         bool do_union = false;
78         bool ccw = false;
79         bool open = false;
80         double factor1 = 1.1;
81         double factor2 = 0.2;
82         int point_count = 50;
83         p_q_settings settings;
84 
85         description.add_options()
86             ("help", "Help message")
87             ("count", po::value<int>(&count)->default_value(1), "Number of tests")
88             ("point_count", po::value<int>(&point_count)->default_value(1), "Number of points in the star")
89             ("diff", po::value<bool>(&settings.also_difference)->default_value(false), "Include testing on difference")
90             ("ccw", po::value<bool>(&ccw)->default_value(false), "Counter clockwise polygons")
91             ("open", po::value<bool>(&open)->default_value(false), "Open polygons")
92             ("wkt", po::value<bool>(&settings.wkt)->default_value(false), "Create a WKT of the inputs, for all tests")
93             ("svg", po::value<bool>(&settings.svg)->default_value(false), "Create a SVG for all tests")
94         ;
95 
96         po::variables_map varmap;
97         po::store(po::parse_command_line(argc, argv, description), varmap);
98         po::notify(varmap);
99 
100         if (varmap.count("help"))
101         {
102             std::cout << description << std::endl;
103             return 1;
104         }
105 
106         int star_point_count = point_count * 2 + 1;
107         int comb_comb_count = point_count;
108 
109 
110         if (ccw && open)
111         {
112             test_all<double, false, false>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
113         }
114         else if (ccw)
115         {
116             test_all<double, false, true>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
117         }
118         else if (open)
119         {
120             test_all<double, true, false>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
121         }
122         else
123         {
124             test_all<double, true, true>(count, star_point_count, comb_comb_count, factor1, factor2, do_union, settings);
125         }
126 
127 #if defined(HAVE_TTMATH)
128         // test_all<ttmath_big, true, true>(seed, count, max, svg, level);
129 #endif
130     }
131     catch(std::exception const& e)
132     {
133         std::cout << "Exception " << e.what() << std::endl;
134     }
135     catch(...)
136     {
137         std::cout << "Other exception" << std::endl;
138     }
139 
140     return 0;
141 }
142