• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <boost/geometry/geometries/register/linestring.hpp>
27 
28 #include <boost/range/adaptor/transformed.hpp>
29 
30 
31 template <typename G>
test_geometry(G const & geo)32 void test_geometry(G const& geo)
33 {
34     typedef typename boost::range_iterator<G const>::type iterator_type;
35 
36 
37     // Run 3 times through the geometry
38     std::size_t n = boost::size(geo) * 3;
39 
40     {
41         std::ostringstream out;
42         bg::ever_circling_iterator<iterator_type> it(boost::begin(geo), boost::end(geo));
43         for (std::size_t i = 0; i < n; ++i, ++it)
44         {
45             out << bg::get<0>(*it);
46         }
47         BOOST_CHECK_EQUAL(out.str(), "123451234512345");
48     }
49 
50     {
51         std::ostringstream out;
52         // Start somewhere
53         bg::ever_circling_iterator<iterator_type> it(
54             boost::begin(geo), boost::end(geo), boost::begin(geo) + 1);
55         for (std::size_t i = 0; i < n; ++i, ++it)
56         {
57             out << bg::get<0>(*it);
58         }
59         BOOST_CHECK_EQUAL(out.str(), "234512345123451");
60     }
61 
62     {
63         std::ostringstream out;
64 
65         // Navigate to somewhere
66         bg::ever_circling_iterator<iterator_type> it(boost::begin(geo), boost::end(geo));
67         for (std::size_t i = 0; i < n; ++i, ++it)
68         {
69             std::size_t const m = boost::size(geo);
70             it.moveto(boost::begin(geo) + m - (i % m) - 1);
71             out << bg::get<0>(*it);
72         }
73         BOOST_CHECK_EQUAL(out.str(), "543215432154321");
74     }
75 
76     // Check the range_iterator-one
77     {
78         std::ostringstream out;
79         bg::ever_circling_range_iterator<G const> it(geo);
80         for (std::size_t i = 0; i < n; ++i, ++it)
81         {
82             out << bg::get<0>(*it);
83         }
84         BOOST_CHECK_EQUAL(out.str(), "123451234512345");
85     }
86 }
87 
88 template <typename G>
test_geometry(std::string const & wkt)89 void test_geometry(std::string const& wkt)
90 {
91     G geo;
92     bg::read_wkt(wkt, geo);
93     test_geometry(geo);
94 }
95 
96 
97 template <typename P>
transform_point(P const & p)98 P transform_point(P const& p)
99 {
100     P result;
101     bg::set<0>(result, bg::get<0>(p) + 1);
102     bg::set<1>(result, bg::get<1>(p) + 1);
103     return result;
104 }
105 
106 template <typename G>
107 struct transformed_geometry_type
108 {
109     typedef typename bg::point_type<G>::type point_type;
110     typedef boost::transformed_range<point_type(*)(point_type const&), G> type;
111 };
112 
113 template <typename G>
test_transformed_geometry(G const & geo)114 void test_transformed_geometry(G const& geo)
115 {
116     typedef typename bg::point_type<G>::type point_type;
117     test_geometry(geo | boost::adaptors::transformed(&transform_point<point_type>));
118 }
119 
120 template <typename G>
test_transformed_geometry(std::string const & wkt)121 void test_transformed_geometry(std::string const& wkt)
122 {
123     G geo;
124     bg::read_wkt(wkt, geo);
125     test_transformed_geometry(geo);
126 }
127 
128 
BOOST_GEOMETRY_REGISTER_LINESTRING(transformed_geometry_type<bg::model::linestring<bg::model::d2::point_xy<double>>>::type)129 BOOST_GEOMETRY_REGISTER_LINESTRING(transformed_geometry_type< bg::model::linestring< bg::model::d2::point_xy<double> > >::type)
130 
131 template <typename P>
132 void test_all()
133 {
134     test_geometry<bg::model::linestring<P> >("linestring(1 1,2 2,3 3,4 4,5 5)");
135     test_transformed_geometry<bg::model::linestring<P> >("linestring(0 0,1 1,2 2,3 3,4 4)");
136 }
137 
test_main(int,char * [])138 int test_main(int, char* [])
139 {
140     test_all<bg::model::d2::point_xy<double> >();
141 
142     return 0;
143 }
144