]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
b32b8144 | 25 | BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) |
7c673cae FG |
26 | |
27 | ||
28 | template <bg::iterate_direction Direction, typename Range> | |
29 | void 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 | ||
53 | template <typename Geometry> | |
54 | void 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 | ||
64 | template <typename P> | |
65 | void 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 | ||
74 | int 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 | } |