PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/algorithms/overlay/enrich_intersection_points.cpp

http://hadesmem.googlecode.com/
C++ | 186 lines | 66 code | 29 blank | 91 comment | 7 complexity | ee9f2a060749e0bfd01b650e64adbf2a MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2// Unit Test
  3
  4// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  5// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  6// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  7
  8// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
 10
 11// Use, modification and distribution is subject to the Boost Software License,
 12// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 13// http://www.boost.org/LICENSE_1_0.txt)
 14
 15#include <iostream>
 16
 17#include <geometry_test_common.hpp>
 18
 19#include <boost/geometry/algorithms/intersection.hpp>
 20
 21//#include <boost/geometry/algorithms/detail/overlay/get_intersection_points.hpp>
 22//#include <boost/geometry/algorithms/detail/overlay/merge_intersection_points.hpp>
 23#include <boost/geometry/algorithms/detail/overlay/enrich_intersection_points.hpp>
 24
 25#include <boost/geometry/strategies/strategies.hpp>
 26
 27#define GEOMETRY_TEST_OVERLAY_NOT_REVERSED
 28
 29#include <overlay_common.hpp>
 30
 31#include <boost/algorithm/string/replace.hpp>
 32
 33
 34#if defined(TEST_WITH_SVG)
 35#  include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
 36#endif
 37
 38struct test_enrich_intersection_points
 39{
 40    static inline std::string dir(int d)
 41    {
 42        return d == 0 ? "-" : (d == 1 ? "L" : "R");
 43    }
 44
 45    template <typename G1, typename G2>
 46    static void apply(std::string const& id,
 47            boost::tuple<int, std::string> const& expected_count_and_center,
 48            G1 const& g1, G2 const& g2, double precision)
 49    {
 50        //std::cout << "#" << id << std::endl;
 51
 52        typedef bg::detail::intersection::intersection_point
 53            <typename bg::point_type<G2>::type> ip;
 54        typedef typename boost::range_const_iterator<std::vector<ip> >::type iterator;
 55        std::vector<ip> ips;
 56
 57        bg::get_intersection_points(g1, g2, ips);
 58        bg::merge_intersection_points(ips);
 59        bg::enrich_intersection_points(ips, true);
 60
 61        std::ostringstream out;
 62        out << std::setprecision(2);
 63
 64        bool first = true;
 65        for (iterator it = boost::begin(ips); it != boost::end(ips); ++it, first = false)
 66        {
 67            out << (first ? "" : ",");
 68            for (unsigned int i = 0; i < it->info.size(); i++)
 69            {
 70                out << dir(it->info[i].direction);
 71            }
 72        }
 73        int n = boost::size(ips);
 74        //std::cout << n << " " << out.str() << std::endl;
 75        BOOST_CHECK_EQUAL(expected_count_and_center.get<0>(), n);
 76        BOOST_CHECK_EQUAL(expected_count_and_center.get<1>(), out.str());
 77
 78
 79
 80#if defined(TEST_WITH_SVG)
 81        {
 82            std::ostringstream filename;
 83            filename << "enrich_ip" << id << ".svg";
 84
 85            std::ofstream svg(filename.str().c_str());
 86
 87            bg::svg_mapper<typename bg::point_type<G2>::type> mapper(svg, 500, 500);
 88            mapper.add(g1);
 89            mapper.add(g2);
 90
 91            mapper.map(g1, "fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");
 92            mapper.map(g2, "opacity:0.8;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");
 93
 94            for (iterator it = boost::begin(ips); it != boost::end(ips); ++it)
 95            {
 96                mapper.map(it->point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
 97            }
 98        }
 99#endif
100    }
101};
102
103
104int test_main(int, char* [])
105{
106    std::vector<boost::tuple<int, std::string> > expected;
107
108    /*
109    TODO Will be refactored
110
111    // NOTE: the order is sometimes not really important, in GCC it is sometimes
112    // different from here...
113
114
115    // 1-6
116    expected.push_back(boost::make_tuple(6, "RL,LR,LR,RL,RL,LR"));
117    expected.push_back(boost::make_tuple(8, "RL,LR,LR,RL,RL,LR,LR,RL"));
118    expected.push_back(boost::make_tuple(4, "RLRR,RRRL,RRRL,RRRL"));
119    expected.push_back(boost::make_tuple(12, "RL,LR,RL,LR,LR,RL,RL,LR,LR,RL,LR,RL"));
120    expected.push_back(boost::make_tuple(17, "LR,RL,LR,RRLR,RL,LR,RL,RL,LR,LR,RL,LR,RL,RL,LR,RL,LR"));
121    expected.push_back(boost::make_tuple(2, "--RR,LR"));
122
123    // 7-12
124    expected.push_back(boost::make_tuple(2, "LL,LL"));
125    expected.push_back(boost::make_tuple(2, "RL--,LL--"));
126    expected.push_back(boost::make_tuple(1, "RLLL"));
127    expected.push_back(boost::make_tuple(2, "RL--,LL--"));
128    expected.push_back(boost::make_tuple(1, "RRLR"));
129    expected.push_back(boost::make_tuple(8, "RL,LR,RL,LR,RL,LR,RL,LR"));
130
131    // 13-18
132    expected.push_back(boost::make_tuple(2, "LL--,LL--"));
133    expected.push_back(boost::make_tuple(2, "RL--,LL--"));
134    expected.push_back(boost::make_tuple(2, "RL--,LL--"));
135    expected.push_back(boost::make_tuple(2, "LL,--RL"));
136    expected.push_back(boost::make_tuple(2, "RR--,--LR"));
137    expected.push_back(boost::make_tuple(2, "RR--,--LR"));
138
139    // 19-24
140    expected.push_back(boost::make_tuple(2, "LL,LL"));
141    expected.push_back(boost::make_tuple(0, ""));
142    expected.push_back(boost::make_tuple(0, ""));
143    expected.push_back(boost::make_tuple(1, "RLLLRRLR"));
144    expected.push_back(boost::make_tuple(2, "RL,RLRRRRLR"));
145    expected.push_back(boost::make_tuple(1, "LRRRRRLR"));
146
147    // 25-30
148    expected.push_back(boost::make_tuple(1, "LRRRLLRL"));
149    expected.push_back(boost::make_tuple(1, "LRLLLLLR"));
150    expected.push_back(boost::make_tuple(2, "LR,LRRRRRRL"));
151    expected.push_back(boost::make_tuple(2, "LR,LRLLRRLR"));
152    expected.push_back(boost::make_tuple(2, "RL,LRRRLLLR"));
153    expected.push_back(boost::make_tuple(2, "LR,LRLLLLRL"));
154
155    // 31-36
156    expected.push_back(boost::make_tuple(1, "--LLLL--"));
157    expected.push_back(boost::make_tuple(1, "LR--LLRL"));
158    expected.push_back(boost::make_tuple(1, "LRLLLL--"));
159    expected.push_back(boost::make_tuple(2, "LR,LRLLRR--"));
160    expected.push_back(boost::make_tuple(1, "LRLLRRLR"));
161    expected.push_back(boost::make_tuple(3, "RL,LR,RLLLRRLR"));
162
163    // 37-42
164    expected.push_back(boost::make_tuple(3, "LRRRRRLR,RL,LR"));
165    expected.push_back(boost::make_tuple(3, "LR--RRRL,LR,RL"));
166    expected.push_back(boost::make_tuple(3, "RL,LR,LRRRRRRL"));
167
168    // 43-48
169    expected.push_back(boost::make_tuple(4, "LR,RL,RL,LR"));
170
171    // 49
172    expected.push_back(boost::make_tuple(16, "--RL,RRLR,RRLR,RL,LLRL,RLLLRRLR,RR--,--LR,RLRR,--LL,RL--,RL,RRRL,RL,LR,RRRLRRRL"));
173
174    // 101
175    expected.push_back(boost::make_tuple(3, "RL,LR,RL"));
176
177    // ticket#17
178    expected.push_back(boost::make_tuple(6, "LR,RL,LR,RL,RL,LR"));
179
180    //test_all<bg::model::d2::point_xy<float>, test_enrich_intersection_points>(expected);
181    test_all<bg::model::d2::point_xy<double>, test_enrich_intersection_points>(expected);
182    //test_all<boost::tuple<double, double>, test_enrich_intersection_points>(expected);
183
184    */
185    return 0;
186}