PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/geometry/test/views/reversible_view.cpp

https://github.com/delalond/boost_1_54_0-bgq
C++ | 81 lines | 56 code | 19 blank | 6 comment | 2 complexity | b0713e38ab5f102c5e10db8ff9736a79 MD5 | raw file
 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#include <algorithm>
11#include <iterator>
12#include <sstream>
13#include <string>
14
15#include <geometry_test_common.hpp>
16
17#include <boost/geometry/views/reversible_view.hpp>
18
19#include <boost/geometry/io/wkt/wkt.hpp>
20#include <boost/geometry/io/dsv/write.hpp>
21#include <boost/geometry/geometries/geometries.hpp>
22#include <boost/geometry/geometries/point_xy.hpp>
23#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
24
25BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian);
26
27
28template <bg::iterate_direction Direction, typename Range>
29void test_forward_or_reverse(Range const& range, std::string const& expected)
30{
31    typedef typename bg::reversible_view
32        <
33            Range const,
34            Direction
35        >::type view_type;
36
37    view_type view(range);
38
39    bool first = true;
40    std::ostringstream out;
41    for (typename boost::range_iterator<view_type const>::type
42        it = boost::begin(view);
43        it != boost::end(view);
44        ++it, first = false)
45    {
46        out << (first ? "" : " ") << bg::dsv(*it);
47    }
48    BOOST_CHECK_EQUAL(out.str(), expected);
49}
50
51
52
53template <typename Geometry>
54void test_geometry(std::string const& wkt,
55            std::string const& expected_forward, std::string const& expected_reverse)
56{
57    Geometry geo;
58    bg::read_wkt(wkt, geo);
59
60    test_forward_or_reverse<bg::iterate_forward>(geo, expected_forward);
61    test_forward_or_reverse<bg::iterate_reverse>(geo, expected_reverse);
62}
63
64template <typename P>
65void test_all()
66{
67    test_geometry<bg::model::linestring<P> >(
68            "linestring(1 1,2 2,3 3)",
69            "(1, 1) (2, 2) (3, 3)",
70            "(3, 3) (2, 2) (1, 1)");
71}
72
73
74int test_main(int, char* [])
75{
76    test_all<bg::model::d2::point_xy<double> >();
77    test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
78    test_all<boost::tuple<double, double> >();
79
80    return 0;
81}