1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2010-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
11 #include <geometry_test_common.hpp>
12
13
14 #include <boost/geometry/geometry.hpp>
15 #include <boost/geometry/geometries/geometries.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/adapted/boost_range/adjacent_filtered.hpp>
18 #include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
19 #include <boost/geometry/geometries/adapted/boost_range/reversed.hpp>
20 #include <boost/geometry/geometries/adapted/boost_range/strided.hpp>
21 #include <boost/geometry/geometries/adapted/boost_range/sliced.hpp>
22 #include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp>
23
24 #include <boost/geometry/io/wkt/wkt.hpp>
25
26 #include <sstream>
27
28 #ifdef BOOST_GEOMETRY_TEST_QUARANTINED
29 struct not_two
30 {
31 template <typename P>
operator ()not_two32 bool operator()(P const& p) const
33 {
34 return boost::geometry::get<0>(p) != 2.0;
35 }
36 };
37
38 struct sum_not_five
39 {
40 template <typename P>
operator ()sum_not_five41 bool operator()(P const& p1, P const& p2) const
42 {
43 return boost::geometry::get<0>(p1) + boost::geometry::get<0>(p2) != 5.0;
44 }
45 };
46 #endif
47
48
49 template <typename P>
test_range_adaptor()50 void test_range_adaptor()
51 {
52 bg::model::linestring<P> ls;
53 bg::read_wkt("LINESTRING(1 1,2 2,3 3,4 4)", ls);
54
55 {
56 std::ostringstream out;
57 out << bg::wkt(ls);
58 BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
59 }
60
61 {
62 std::ostringstream out;
63 out << bg::wkt(ls | boost::adaptors::reversed);
64 BOOST_CHECK_EQUAL(out.str(), "LINESTRING(4 4,3 3,2 2,1 1)");
65 }
66
67 {
68 std::ostringstream out;
69 out << bg::wkt(ls | boost::adaptors::strided(2));
70 BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3)");
71 }
72
73 {
74 std::ostringstream out;
75 out << bg::wkt(ls | boost::adaptors::sliced(1,3));
76 BOOST_CHECK_EQUAL(out.str(), "LINESTRING(2 2,3 3)");
77 }
78
79 #ifdef BOOST_GEOMETRY_TEST_QUARANTINED
80 // range filter adaptor does not support boost::size()
81 // This makes it in practice not applicable, boost::geometry calls boost::size
82 // in most if not all algorithms
83 {
84 std::ostringstream out;
85 out << bg::wkt(ls | boost::adaptors::filtered(not_two()));
86 BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
87 }
88
89 {
90 std::ostringstream out;
91 out << bg::wkt(ls | boost::adaptors::adjacent_filtered(sum_not_five()));
92 BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
93 }
94
95 {
96 bg::model::linestring<P> ls2;
97 bg::read_wkt("LINESTRING(1 1,1 1,2 2,3 3,3 3,4 4)", ls2);
98 std::ostringstream out;
99
100
101 // uniqued needs == operator, equals
102 //out << bg::wkt(ls | boost::adaptors::uniqued);
103 //BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
104 }
105 #endif
106 }
107
108 template <typename P>
test_all()109 void test_all()
110 {
111 test_range_adaptor<P>();
112 }
113
114
115
test_main(int,char * [])116 int test_main(int, char* [])
117 {
118 test_all<bg::model::d2::point_xy<double> >();
119 test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
120
121 return 0;
122 }
123
124