PageRenderTime 63ms CodeModel.GetById 49ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/algorithms/overlay/robustness/star_comb.cpp

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