#### /Src/Dependencies/Boost/libs/geometry/test/geometries/boost_range.cpp

C++ | 116 lines | 80 code | 27 blank | 9 comment | 2 complexity | dd1b0d92c6bd1b9426c6e0b22a0cd2e7 MD5 | raw file
```  1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2010 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
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>
23
24#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
25
26#include <sstream>
27
28struct not_two
29{
30    template <typename P>
31    bool operator()(P const& p) const
32    {
33        return boost::geometry::get<0>(p) != 2.0;
34    }
35};
36
37struct sum_not_five
38{
39    template <typename P>
40    bool operator()(P const& p1, P const& p2) const
41    {
42        return boost::geometry::get<0>(p1) + boost::geometry::get<0>(p2) != 5.0;
43    }
44};
45
46
47template <typename P>
49{
50    bg::model::linestring<P> ls;
51    bg::read_wkt("LINESTRING(1 1,2 2,3 3,4 4)", ls);
52
53    {
54        std::ostringstream out;
55        out << bg::wkt(ls);
56        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
57    }
58
59    {
60        std::ostringstream out;
61        out << bg::wkt(ls | boost::adaptors::reversed);
62        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(4 4,3 3,2 2,1 1)");
63    }
64
65    {
66        std::ostringstream out;
67        out << bg::wkt(ls | boost::adaptors::strided(2));
68        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3)");
69    }
70
71    {
72        std::ostringstream out;
73        out << bg::wkt(ls | boost::adaptors::sliced(1,3));
74        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(2 2,3 3)");
75    }
76
77    {
78        std::ostringstream out;
79        out << bg::wkt(ls | boost::adaptors::filtered(not_two()));
80        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
81    }
82
83    {
84        std::ostringstream out;
86        BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)");
87    }
88
89    {
90        bg::model::linestring<P> ls2;
91        bg::read_wkt("LINESTRING(1 1,1 1,2 2,3 3,3 3,4 4)", ls2);
92        std::ostringstream out;
93
94
95        // uniqued needs == operator, equals
96        //out << bg::wkt(ls | boost::adaptors::uniqued);
97        //BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)");
98    }
99}
100
101template <typename P>
102void test_all()
103{
105}
106
107
108
109int test_main(int, char* [])
110{
111    test_all<bg::model::d2::point_xy<double> >();
112    test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
113
114    return 0;
115 }
116
```