1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 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 <sstream>
16 #include <string>
17 
18 #include <geometry_test_common.hpp>
19 
20 #include <boost/geometry/iterators/ever_circling_iterator.hpp>
21 
22 #include <boost/geometry/core/coordinate_type.hpp>
23 #include <boost/geometry/io/wkt/read.hpp>
24 #include <boost/geometry/geometries/geometries.hpp>
25 #include <boost/geometry/geometries/point_xy.hpp>
26 
27 template <typename G>
test_geometry(std::string const & wkt)28 void test_geometry(std::string const& wkt)
29 {
30     G geo;
31     bg::read_wkt(wkt, geo);
32     typedef typename boost::range_iterator<G const>::type iterator_type;
33 
34 
35     // Run 3 times through the geometry
36     int n = boost::size(geo) * 3;
37 
38     {
39         std::ostringstream out;
40         bg::ever_circling_iterator<iterator_type> it(boost::begin(geo), boost::end(geo));
41         for (int i = 0; i < n; ++i, ++it)
42         {
43             out << bg::get<0>(*it);
44         }
45         BOOST_CHECK_EQUAL(out.str(), "123451234512345");
46     }
47 
48     {
49         std::ostringstream out;
50         // Start somewhere
51         bg::ever_circling_iterator<iterator_type> it(
52             boost::begin(geo), boost::end(geo), boost::begin(geo) + 1);
53         for (int i = 0; i < n; ++i, ++it)
54         {
55             out << bg::get<0>(*it);
56         }
57         BOOST_CHECK_EQUAL(out.str(), "234512345123451");
58     }
59 
60     {
61         std::ostringstream out;
62 
63         // Navigate to somewhere
64         bg::ever_circling_iterator<iterator_type> it(boost::begin(geo), boost::end(geo));
65         for (int i = 0; i < n; ++i, ++it)
66         {
67             const int m = boost::size(geo);
68             it.moveto(boost::begin(geo) + m - (i % m) - 1);
69             out << bg::get<0>(*it);
70         }
71         BOOST_CHECK_EQUAL(out.str(), "543215432154321");
72     }
73 
74     // Check the range_iterator-one
75     {
76         std::ostringstream out;
77         bg::ever_circling_range_iterator<G> it(geo);
78         for (int i = 0; i < n; ++i, ++it)
79         {
80             out << bg::get<0>(*it);
81         }
82         BOOST_CHECK_EQUAL(out.str(), "123451234512345");
83     }
84 }
85 
86 template <typename P>
test_all()87 void test_all()
88 {
89     test_geometry<bg::model::linestring<P> >("linestring(1 1,2 2,3 3,4 4,5 5)");
90 }
91 
test_main(int,char * [])92 int test_main(int, char* [])
93 {
94     test_all<bg::model::d2::point_xy<double> >();
95 
96     return 0;
97 }
98